The property function.length
indicates the number of parameters a function expects
GIVEN reading the length
of an old-style defined function (exists since ES1)
WHEN reading the property length
of a function without parameters THEN the this returns 0
GIVEN we read the length
property of an arrow function
WHEN reading length
on a function with two named parameters THEN it returns 2
WHEN function has a single optional parameter THEN length
returns 0
WHEN function only has a rest parameter THEN length
returns 0
WHEN function has a single named parameter and a rest parameter THEN length
returns 1
WHEN function has one named, one optional, and a rest parameter THEN length
returns 1
GIVEN reading length
where the function has destructured parameters
WHEN the first parameter reads two values using destructuring THEN length
is still 1
WHEN two destructured parameters are defined THEN the length
is 2
Links
The specification text, which is the same as in the initial introduction of this property, in ES1.
The MDN pages describing this property, easy to read with examples.