Intermediate JavaScript Interview QuestionsIntermediateComparison
JavaScript · Question 37
What is the difference between call(), apply(), and bind() in JavaScript?
Direct answer
call and apply invoke a function immediately with an explicit this value; call receives arguments individually, apply receives an array-like argument list, while bind returns a new function with this and optional leading arguments fixed.
call() and apply() are immediate invocation tools. bind() is a function-creation tool.
fn.call(user, 1, 2)→ execute now withthis === userand positional arguments.fn.apply(user, [1, 2])→ execute now with the arguments supplied as an array-like value.const bound = fn.bind(user, 1)→ return a new function; callingbound(2)later supplies the remaining argument.
Modern spread syntax means apply() is less necessary merely to expand an array: fn(...args) is usually clearer when no explicit receiver is needed.