© Gennaro Nucaro 2026 | All Rights Reserved
Complete Guide to this, call, apply, and bind
this in JavaScriptIn JavaScript, the keyword this is a special identifier that refers to the context in which a function is executed. It determines the behavior of functions and which object they belong to. In short, this indicates the usage context. We will see various examples to understand how this points to the context and how it can be explicitly bound to a specific object or function call.
this?this refers to the object from which the method or function in which it is used was invoked, but its value can vary depending on the call context.
thisthis in Strict and Non-Strict ModeIn non-strict mode, this is always a reference to an object. In strict mode, however, it can be any value.
Here is an example showing how the value of this changes based on the mode:
In the global context, this refers to the global object. In a browser, this object is window.
In a function not in strict mode, this refers to the global object.
In strict mode, this is undefined.
When this is used within an object method, it refers to the object itself.
When this is used within a constructor, it refers to the instance of the object created by the constructor function.
Using constructor function syntax:
Using ES6 class syntax:
Arrow functions do not have their own this. Instead, they inherit this from the surrounding execution context at the time of their creation.
In the above case, this within the arrow function refers to the global context, not the person object.
call, apply, and bind Methods in JavaScriptJavaScript offers three fundamental methods to manage the context (this) in functions: call(), apply(), and bind(). These methods allow you to modify the context in which a function is executed, which can be particularly useful for controlling function behavior.
callThe call method allows you to call a function with a specific value of this and a series of arguments passed individually.
applyThe apply method is similar to call, but instead of passing arguments individually, they are passed as an array or array-like object.
bindThe bind method creates a new function that, when called, has its this value set to a specific value and, optionally, a series of preset arguments.
call, apply, and bindcall when you want to immediately execute a function with a specific value of this and a series of individually passed arguments.apply when you want to immediately execute a function with a specific value of this and an array of arguments.bind when you want to create a new function with a predefined this value and, optionally, preset arguments, to be called later.Understanding call, apply, and bind is essential for mastering the behavior of this in JavaScript and writing more flexible and reusable code. By using these methods, you can precisely control the execution context of your functions, improving the readability and maintainability of your code.
© Gennaro Nucaro 2026 | All Rights Reserved