Javascript/this Keyword
Javascript / Topic

this Keyword

Understand how the 'this' keyword works in different execution contexts and how JavaScript determines its value.

Difficulty

Intermediate

Read time

15 min

Format

Concept + Code

Focus

Interview ready
Concepts
this
Execution Context
Arrow Functions
Interview

01 / Foundation

Understand the concept

The value of 'this' is determined by how a function is invoked, not where it is defined.

Understanding 'this' is essential because it behaves differently in regular functions, arrow functions, object methods, constructors, and event handlers.

02 / Implementation

Object Method vs Regular Function

this.js
const person = {
  name: "John",

  greet() {
    console.log(this.name);
  },
};

person.greet(); // John

const greet = person.greet;

greet(); // undefined (strict mode)

04 / Interview

Test your understanding