Skip to content
IT glossary
FrontendUpdated December 3, 2026

this in JavaScript

this в JavaScript

The `this` keyword lets a function refer to a value, often the object it should work on. For a regular function, that value depends on how it is called. An arrow function takes `this` from its surrounding code.

Also known as: bind, call, apply

What this is for

A method can read this.name without hard-coding which object supplies the name. In user.describe(), this inside a regular method is user. If another object uses that same function as a method, it can supply a different this. Think of this as an input to the call, separate from the arguments inside the parentheses.

How JavaScript picks the value

  • Method call: In team.lead.describe(), the receiver is team.lead, not team. What matters is the object used to make the call, even if the method was inherited from a prototype.
  • Standalone call: const describe = user.describe copies the function reference, not the receiver. A later describe() gets undefined as this if the function is strict, or the global object if it is not. Code in ES modules is always strict.
  • Constructor call: With new, a base constructor gets the new instance as this. In a derived class constructor, this is unavailable until super() initializes it.
  • Arrow function: An arrow doesn't have its own this. It uses the surrounding this, so an arrow created inside a method can keep using that method's receiver. Putting an arrow in an object literal doesn't make that object its this.

Choosing this with call, apply, and bind

Use fn.call(receiver, a, b) to invoke a function immediately with a chosen receiver and individual arguments. fn.apply(receiver, [a, b]) also calls it immediately but takes the arguments as an array or array-like object. fn.bind(receiver, a) returns a new function for later use and can prefill leading arguments. For an arrow function, none of these methods can change this.

const account = {
  owner: 'Maya',
  label(prefix) { return `${prefix}: ${this.owner}`; }
};

const label = account.label;
console.log(label.call({ owner: 'Lee' }, 'Owner')); // Owner: Lee
console.log(label.apply(account, ['Owner']));       // Owner: Maya
const accountLabel = label.bind(account, 'Owner');
console.log(accountLabel());                       // Owner: Maya

The callback trap

Passing account.label as a callback doesn't preserve account as its receiver. The API decides how to invoke the callback. If the method must use account, pass a bound function or a wrapper such as prefix => account.label(prefix). If you register a bound function as a DOM listener, keep that exact function reference so you can remove it later. Calling bind again creates a different function.

What interviewers look for

When asked to predict what a snippet prints, identify the kind of function first. For an arrow, trace this outward to the surrounding code. For a regular function, find the actual call: is it a method call, a constructor call, or a call with an explicit or bound receiver? If it's a standalone call, check whether the function is strict before deciding what this will be.