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

Too Many Arguments: Extra Values

Learn how JavaScript handles extra arguments that don't match any parameter.

What You'll Learn

You'll learn what happens when you call a function with more arguments than it has parameters — and why JavaScript won't complain.

The Permissive Nature of JavaScript

JavaScript has a surprisingly relaxed attitude toward function calls. If you pass more arguments than the function has parameters, JavaScript simply ignores the extras. No error is thrown, and your code continues running as if nothing unusual happened.

Think of it like ordering pizza toppings: if you ask for pepperoni, mushrooms, and olives, but the order form only has two slots, the first two make it onto your pizza and the third is quietly forgotten.

Example

function greet(name, age) {
  console.log(`Hello, ${name}. You are ${age}.`);
}

greet('Alice', 30, 'Engineer', true, 42);
// Output: Hello, Alice. You are 30.

Here we passed five arguments but greet only has two parameters (name and age). The last three values ('Engineer', true, 42) are completely ignored — they don't cause an error, don't get stored anywhere you can see, and don't affect the function's behavior.

Why This Matters

This flexibility can be both convenient and dangerous:

  • Convenient: You can add optional features later without breaking existing calls
  • Dangerous: Typos or misunderstandings won't produce errors, making bugs harder to spot
function add(a, b) {
  return a + b;
}

add(5, 10, 20); // Returns 15, not 35 — the 20 is silently ignored

If you expected all three numbers to be summed, you'd get the wrong result with no warning.

Key Takeaway: JavaScript silently ignores extra arguments that don't match any parameter — the function only "sees" values up to the number of parameters it defines.