The Wayback Machine - https://web.archive.org/web/20260327214716/https://www.geeksforgeeks.org/node-js/node-js-this-binding/

Node.js This Binding

Last Updated : 6 Mar, 2026

Arrow functions do not bind their own this and instead inherit it from the surrounding scope. This makes them useful for callbacks but unsuitable for object methods.

  • Arrow functions use lexical this from the outer scope.
  • Not suitable for object methods because this won’t refer to the object.
  • ES6 method shorthand should be used for defining methods.
  • Ideal for callbacks like forEach where outer this access is needed.

Filename: index.js

javascript
// 'This' in Arrow function
const eventOne = {
    name: 'Birthday Party',
    guestList: ['Ginny', 'Nicol'],
    printGuestList() {
        console.log('Guest list for ' + this.name);
        this.guestList.forEach((guest) => {
            console.log(guest + ' is attending ' + this.name)
        });
    }
}

// 'This' in normal function
const eventTwo = {
    name: 'Birthday Party',
    guestList: ['Ginny', 'Nicol'],
    printGuestList() {
        console.log('Guest list for ' + this.name);
        this.guestList.forEach(function (guest) {
            console.log(guest + ' is attending ' + this.name)
        });
    }
}

eventOne.printGuestList();
console.log('---------------------');
eventTwo.printGuestList();

Run index.js file using the following command:

node index.js
Screenshot-2026-03-06-182721

So this is how 'this' binding works on arrow functions and normal functions.

Comment

Explore