Parameters & Return Values
Learn how to pass data into functions and get results back out.
Step 1 of 6
Parameters: filling in the blanks
So far our functions have done the exact same thing every time. But real functions need to work with different data. Parameters are variables listed inside the parentheses of a function declaration — they act as placeholders for the actual values you'll provide when you call the function. When you call `greet("Alice")`, the string `"Alice"` gets assigned to the parameter `name` inside the function. The value you pass in is called an argument. Think of it this way: the parameter is the blank on the form, the argument is what you fill in.
Think of it this way: Parameters are like blanks in a Mad Libs story. The function is the template: 'Make a sandwich with _____ and _____.' You fill in the blanks each time you use it — 'Make a sandwich with turkey and cheese' or 'Make a sandwich with peanut butter and jelly.' Same recipe, different ingredients.
Web Standard
Technically, 'parameter' refers to the variable in the function definition, and 'argument' refers to the actual value passed when calling the function. Many developers use the terms interchangeably, but knowing the difference helps when reading documentation.
Learn more on MDN
JAVASCRIPTREAD ONLY
CONSOLE
Click "Run" to execute your code...