The Bind method creates a new function that, when called, has
this value set to the provided value, with a given sequence of arguments preceding any provided when the new function is called. Unlike
call and apply, bind does not invoke the function immediately; it returns a new function.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
JavaScript call, apply, and bind Methods
In JavaScript, calls, implementations, and bindings are methods for modifying the context (this keyword) in which the operation is performed.
Each has specific usage and grammatical differences.
call() Method
The
callmethod invokes the function giventhisvalues and one by one with the given arguments.Syntax-
Example-
apply() Method
The
apply()method calls a function that is giventhisvalue, but the argument is given as an array (or array-like object).Syntax-
Example-
bind() Method
The
Bindmethod creates a new function that, when called, hasthisvalue set to the provided value, with a given sequence of arguments preceding any provided when the new function is called. Unlikecallandapply,binddoes not invoke the function immediately; it returns a new function.Syntax-
Example-
The main differences
Invocation
Syntax
Use Case
callwhen you know the level of dispute and want to call the function immediately.applywhen you have an array of arguments and you want to call the function immediately.bindwhen you want to create a new function with that particularthisvalue and/or with default arguments, to call later.Understanding these methods and their differences is important for proper implementation and context management in JavaScript.
Also, Read: What is JavaScript's spread operator (...), and how is it used?