JS: Function parameters

By Xah Lee. Date: . Last updated: .

Number of arguments not checked

JavaScript does not check the number of arguments passed in a function call.

// extra arguments are ignored.
function ff(x) {
 return x;
}
console.assert(ff(2, 3, 4) === 2);
// extra arguments are ignored.
// for arrow function too.
const gg = (x) => x;
console.assert(gg(2, 3, 4) === 2);
// unfilled parameters have value of undefined

function ff(x, y) {
 return y;
}

const gg = (x, y) => y;

console.assert(ff(3) === undefined);

console.assert(gg(3) === undefined);

Parameter default value

Rest parameters

Function argument binding pattern

The arguments object

How to find out how many parameters are required?