Skip to content
UniCircle
TipEngineeringB.Tech / B.E., BCA, MCA

The this keyword in JavaScript, explained with four rules

How this is decided at call time, why arrow functions behave differently, and how to fix the lost-this bug in callbacks.

By UniCircle team1 min readPublished 22 Oct 2026Undergraduate

For a normal function, this is decided by how the function is called, not where it is written. Four rules cover almost every case:

  1. Called as obj.method(): this is obj.
  2. Called with new: this is the newly created object.
  3. Called with call, apply or bind: this is whatever you pass.
  4. Called plainly, as fn(): this is undefined in strict mode (classes and modules are strict).

Arrow functions ignore all four: they use the this of the code around them.

JavaScript
'use strict';
const student = {
  name: 'Asha',
  hello() { return `Hi, ${this.name}`; },
  later() { return [1].map(() => this.name)[0]; }
};
console.log(student.hello());
const loose = student.hello;
try { loose(); } catch (e) { console.log('lost this:', e.constructor.name); }
console.log(loose.call({ name: 'Ravi' }));
const bound = student.hello.bind(student);
console.log(bound(), student.later());
text
Hi, Asha
lost this: TypeError
Hi, Ravi
Hi, Asha Asha

The lost-this bug

Passing obj.method as a callback (to setTimeout, an event listener or map) detaches it from obj, so this is lost. Fix it with bind, or wrap the call: () => obj.method(). In classes, arrow-function class fields are a common fix for event handlers.

#javascript#this#arrow functions#bind

Sources and further reading

Practise this as an interview question

Written by the UniCircle team, checked by an editor on 22 Oct 2026. It is not official policy of any university. Exam patterns and rules change; confirm dates and rules on the official website.

Keep reading