#78: f.length with a default and a rest param
Topic: misc · Difficulty: ★
function f(a, b, c = 1, ...rest) {}
console.log(f.length);Output
2
Why
A function's .length property reports its arity: the count of parameters BEFORE the first one with a default value or a rest pattern — not the total number of parameters written. f has four parameters, but c = 1 is the first one with a default, so counting stops there: only a and b are counted, giving length 2. Parameters after a default (like c itself) and any rest parameter (...rest) are excluded no matter how many there are, because .length is meant to describe how many arguments MUST be supplied for the function to behave normally.