Functions with parameters
This function contains a parameter.
- function keyword to define a function
- the name of the function in lowerCamelCase: getLower
- (name): the parentheses containing the parameter name
- the opening curly brace:
{
- the function body. In this example, return name.toLowerCase() returns a copy of the name in lowercase.
- the closing curly brace:
}
function getLower(name) {
return name.toLowerCase()
}
Two or more parameters
- Parameters go inside the parentheses ().
- When you have more than one parameter, you must separate them with a comma character.
function sum(a, b) {
return a + b
}