To create a function in JavaScript with parameters, you can simply declare the parameter names inside the parentheses of the function declaration. Here is an example:
index.tsx99 chars6 lines
In the example above, we have declared a function called greet
that takes a single parameter called name
. Inside the function, we are logging a string to the console using template literals.
When we call the greet
function and pass in the argument 'John'
, the function will log the message "Hello, John!" to the console.
You can also define multiple parameters, separated by commas, like this:
index.tsx77 chars6 lines
In this example, the sum
function takes two parameters a
and b
, and returns their sum, which is then logged to the console.
gistlibby LogSnag