LESSON 17

Parameters

Learning objective: Pass information into functions with parameters.

Understand

Parameters let functions work with different inputs.

Parameters are named inputs listed in a function's definition; the values you pass when calling are arguments. This makes one function flexible enough to handle many cases.

Analogy: Parameters are like the blanks in a form the function fills in with whatever you provide.

See It in Action

A parameterized greeting:

function greet(name) {
  console.log(`Hi, ${name}!`);
}
greet("Sam");
greet("Ada");
How it works: name is the parameter; 'Sam' and 'Ada' are arguments, so the same function greets different people.

Try It Yourself

  1. Add a parameter to a function.
  2. Call it with two different arguments.
  3. Add a second parameter.

Quick Quiz

What is the difference between a parameter and an argument?

Challenge

Write a function that takes a name and greets that person.

Success condition: Your function greets different people based on the argument.