JavaScript Fundamentals / Functions

Arguments vs Parameters

🟡 What Are Parameters?

  • Parameters are the placeholders or variables listed inside a function’s parentheses.

  • They define what kind of input the function expects.

  • They are part of the function definition.

Example:

function sum(a, b) {
		// ↑  ↑
	  // parameters
  return a + b;
}

Here, a and b are parameters.


🟢 What Are Arguments?

  • Arguments are the actual values you pass to a function when calling it.

  • They replace the parameters in the function.

Example:

sum(5, 10);
 // ↑   ↑
// arguments

Here, 5 and 10 are arguments.


🔍 In Simple Words

  • Parameters = variables in the function definition

  • Arguments = values passed when calling the function


📝 Key Points

  • Parameters act like local variables inside the function.

  • Arguments fill in the parameters when the function is executed.

  • Number of arguments should ideally match number of parameters (though JavaScript doesn’t enforce it).

  • Extra arguments are ignored; missing ones become undefined.