Q1. What are parameters in JavaScript?
Parameters are variables listed in the function definition. They act as placeholders for values that will be passed to the function.
Parameters allow functions to accept input values and work dynamically based on those inputs.
Example
Here, name is a parameter.
Parameters allow functions to accept input values and work dynamically based on those inputs.
Example
function greet(name) { return "Hello " + name;}Here, name is a parameter.
Q2. What are arguments?
Arguments are the actual values passed to a function when it is called.
Arguments replace the parameters when the function executes.
Example
Here, "John" is an argument.
Arguments replace the parameters when the function executes.
Example
greet("John");Here, "John" is an argument.
Q3. Can a function have multiple parameters?
Yes, a function can have multiple parameters.
Example
Example
function add(a, b) { return a + b;}
console.log(add(5, 3));Q4. What happens if fewer arguments are passed than parameters?
If fewer arguments are passed, the missing parameters will have the value undefined.
Example
Output
Example
function show(a, b) { console.log(a, b);}
show(10);Output
10 undefinedQ5. What happens if more arguments are passed than parameters?
Extra arguments are ignored unless accessed using special techniques like the arguments object or rest parameters.
Example
Here, 4 is ignored.
Example
function sum(a, b) { return a + b;}
console.log(sum(2, 3, 4));Here, 4 is ignored.
