Lesson 3: Function Parameters and Arguments

Learning Objectives

By the end of this lesson, learners will be able to:

  • Understand what parameters and arguments are
  • Define functions that accept input values
  • Pass data into functions when calling them
  • Use multiple parameters
  • Recognize the importance of dynamic, reusable functions

What Are Parameters and Arguments?

When you define a function, you can specify parameters — placeholders for values you want the function to use.

When you call the function, you provide arguments — the actual values you pass to the function.


Terminology

TermDescription
ParameterA named variable in the function definition
ArgumentThe actual value passed when calling the function

Syntax Example

Step 1: Define a function with a parameter

function greetUser(name) {
  console.log("Hello, " + name + "!");
}
  • name is a parameter – a placeholder for any name

Step 2: Call the function with an argument

greetUser("Anna"); // Hello, Anna!
greetUser("Liam"); // Hello, Liam!
  • "Anna" and "Liam" are arguments

✅ Each time, the function personalizes the greeting.


Why Use Parameters?

Without parameters:

function greetAnna() {
  console.log("Hello, Anna!");
}

With parameters:

function greetUser(name) {
  console.log("Hello, " + name + "!");
}

✅ You can greet any user, not just Anna.


Multiple Parameters

Functions can take more than one parameter:

function printFullName(firstName, lastName) {
  console.log("Full Name: " + firstName + " " + lastName);
}

printFullName("Ada", "Lovelace"); // Full Name: Ada Lovelace
  • firstName and lastName are parameters
  • "Ada" and "Lovelace" are arguments

Example: Calculate Area

function calculateArea(width, height) {
  let area = width * height;
  console.log("Area: " + area);
}

calculateArea(5, 3); // Area: 15

✅ You can reuse the function with different values anytime.


What If No Argument Is Given?

function greet(name) {
  console.log("Hello, " + name);
}

greet(); // Output: Hello, undefined
  • If you don’t pass an argument, the parameter becomes undefined.
  • You can avoid this using a default value (covered in later lessons).