Friday, April 27, 2018

Function object - length property

Using length property with function object, will return how many parameters the function using.

Example:


function first(a) {}
function second(a, b) {}
function multiple(a, b, ...more) {}

alert(first.length); // 1
alert(second.length); // 2
alert(multiple.length); // 2

Note: The last one, multiple function showing parameter length as 2. Because rest parameters(...) will not be calculated.


No comments:

Post a Comment