Problem Statement
Which statement is true about call, apply, and bind?
Explanation
call(thisArg, ...args) and apply(thisArg, argsArray) invoke the function immediately with a specified this. bind(thisArg, ...args) returns a new function with this and optional arguments pre-set.
Code Solution
SolutionRead Only
function add(a, b){ return this.x + a + b; }
const ctx = { x: 10 };
console.log(add.call(ctx, 1, 2)); // 13
console.log(add.apply(ctx, [1, 2])); // 13
const bound = add.bind(ctx, 1);
console.log(bound(2)); // 13Practice Sets
This question appears in the following practice sets:
