jskatas.org Continuously Learn JavaScript. Your Way.

function API: function.length (with ES5 features)

The length property indicates the number of parameters a function expects.

The property function.length indicates the number of parameters a function expects

GIVEN we read the length from a bound function

WHEN binding a function with 3 parameters THEN the bound value has still a length of 3
const fn = function(a, b, c) {}; const boundFn = fn.____(null); assert.equal(boundFn.length, 3);
WHEN binding a function (that expects three parameters) with one parameter THEN the length will reduced by 1, it will be 2
const fn = function(a, b, c) {}; const boundFn = fn.bind(null, 1, 2, 3); assert.equal(boundFn.length, 2);

Links

The MDN docs about `length`.
The ECMAScript Language Specification, 5 Edition, Section 15.3.5.1.

Required Knowledge

Related Katas

function API

Arrow functions

Async Function

Difficulty Level

BEGINNER

First Published

18 October 2023

Stats

2 tests to solve