this
In JavaScript, the this keyword is an expression that evaluates to the object a function was called on, or to another value set by how and where the code runs. In most functions, its value is decided by the call, not by where the function is defined.
In a call like object.method(), this is object. A function called with new gets the newly created object, and a derived class constructor gets its this only after super() runs. An arrow function has no this of its own and uses the one from the surrounding code. A plain function call gets undefined in strict mode and the global object in sloppy mode. The full rules are covered under this binding.
At the top level, this is globalThis in a classic script and undefined in an ES module. Node.js wraps each CommonJS file in a function, so this at the top of one is module.exports. Assigning to this is a SyntaxError. The keyword dates from the first edition of ECMAScript.
JavaScript this Keyword Examples
A method reads this from the object it’s called on:
> const counter = {
… count: 0,
… increment() {
… this.count += 1;
… return this.count;
… },
… };
undefined
> counter.increment()
1
> const other = { count: 10, increment: counter.increment };
undefined
> other.increment()
11
Both objects share one function, but each call reads this from the object before the dot.
Calling a class method without its object leaves this as undefined, because class code is always strict:
> class Timer {
… constructor() {
… this.ticks = 0;
… }
… tick() {
… this.ticks += 1;
… return this.ticks;
… }
… }
undefined
> const timer = new Timer();
undefined
> const { tick } = timer;
undefined
> try { tick(); } catch (error) { console.log(error.name); }
TypeError
undefined
> const boundTick = timer.tick.bind(timer);
undefined
> boundTick()
1
The detached call has no receiver, so this.ticks throws. The .bind() method fixes this to timer.
JavaScript this Keyword Use Cases
- Reading and updating an object’s own state from its methods
- Initializing instance fields in a class constructor
- Sharing one method across several objects
- Referring to the class itself from a
staticmethod
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 3, 2026