OneBite.Dev - Coding blog in a bite size

declare a function with single parameter in Javascript

Code snippet on how to declare a function with single parameter in Javascript

  function sayHello(name) {
    return console.log(`Hello, ${name}!`);
  }

This code declares a function called sayHello which takes a single parameter name. The function uses console.log to display a string, with the parameter name included inside the string. Specifically, it uses a template literal to concatenate the strings Hello, and ! along with the parameter name. Inside the function, the line return is used, which means the function will output whatever is given after the return keyword. In this case, it will return the string provided by the console.log statement.

javascript