Parameters and Return Values
👨💼 Functions become much more powerful when they can receive input and produce
output.
- Parameters are variables that receive values when the function is called
- Return values let functions send data back to the caller
The syntax:
function add(a, b) {
return a + b
}
const result = add(5, 3) // result is 8
- Create a function
greetPersonthat takes anameparameter and returns a greeting string like "Hello, [name]!" - Create a function
multiplythat takes two numbers and returns their product - Create a function
isEventhat takes a number and returnstrueif even,falseif odd - Call each function and log the results
💰 Remember:
return stops the function and sends back a value. Without
return, functions return undefined.