Course contentsShow
← JavaScript
Lesson 404 of 2,72311. FunctionsFree lesson

Positional Parameters

Understand how parameters are matched to arguments by position in the function call.

Positional Parameters

What you'll learn: How JavaScript matches each argument you pass in a function call to the correct parameter by the order they appear.

The Core Idea

When you define a function with multiple parameters, JavaScript doesn't match them by name when you call the function—it matches them by position. The first argument you pass becomes the value of the first parameter, the second argument becomes the second parameter, and so on.

Think of it like a relay race: each runner (argument) must hand the baton to their assigned teammate (parameter) in exact order. Skip the order, and the wrong person gets the baton.

How It Works

function greet(firstName, lastName) {
  return `Hello, ${firstName} ${lastName}!`;
}

greet("Alice", "Smith");  // "Hello, Alice Smith!"
greet("Smith", "Alice");  // "Hello, Smith Alice!" - wrong order!

Notice how swapping the arguments changes the result. JavaScript doesn't "know" which is a first name or last name—it only knows position.

Multiple Parameters Example

function calculatePrice(price, tax, discount) {
  return price + tax - discount;
}

calculatePrice(100, 15, 10);  // 105
calculatePrice(15, 100, 10);  // 105 (but wrong meaning!)

Even though both calls return 105, the second one makes no logical sense (a 15itemwith15 item with 100 tax). Position matters for correctness, not just computation.

Skipping Arguments

function display(a, b, c) {
  console.log(a, b, c);
}

display(1, 2);  // 1 2 undefined (c has no matching argument)

Key Takeaway: JavaScript matches arguments to parameters strictly by their order in the function call—the first argument always goes to the first parameter, the second to the second, and so on, regardless of what they represent.