JavaScript this

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

this is the receiver of a function call. In a method, it is usually the object before the dot. Arrow functions do not bind their own thisโ€”they use the surrounding one.

JavaScript Syntax

JavaScript
const user = {
  name: "Ada",
  hello() { return "Hi " + this.name; }
};
console.log(user.hello());
Try it Editor

How It Works

  1. Method call. user.hello() sets this to user.
  2. this.name. Reads Ada.

Examples

Example 1 — Losing this

Extracting a method can lose the object.

JavaScript
const user = { name: "Ada", hello(){ return this.name; } };
const fn = user.hello;
console.log(typeof fn());
Try it Editor

How It Works

  1. fn() is a plain call.
  2. this is not user (undefined in strict mode).

Example 2 — bind fixes it

Function.prototype.bind.

JavaScript
const user = { name: "Ada", hello(){ return this.name; } };
const fn = user.hello.bind(user);
console.log(fn());
Try it Editor

How It Works

  1. bind locks this to user.

Example 3 — Arrow lexical this

Arrows capture outer this.

JavaScript
const user = { name: "Ada", hi(){ const a = () => this.name; return a(); } };
console.log(user.hi());
Try it Editor

How It Works

  1. Arrow uses hi's this.

Frequently Asked Questions

The object (or undefined/global) that a function was called with as its receiver.
They inherit this from the enclosing scope; they do not get a new this from how they are called.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P ๐Ÿ”—

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful