Back to Browse

What is THIS in JavaScript? πŸ‘ˆ

56.3K views
Nov 15, 2023
4:27

#JavaScript #tutorial #course // this = reference to the object where THIS is used // (the object depends on the immediate context) const person1 = { name: "Spongebob", favFood: "hamburgers", sayHello: function(){console.log(`Hi! I am ${this.favFood}`)}, eat: function(){console.log(`${this.name} is eating ${this.favFood}`)} } const person2 = { name: "Patrick", favFood: "pizza", sayHello: function(){console.log(`Hi! I am ${this.favFood}`)}, eat: function(){console.log(`${this.name} is eating ${this.favFood}`)} } person1.eat(); person2.eat();

Download

1 formats

Video Formats

360pmp45.5 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

What is THIS in JavaScript? πŸ‘ˆ | NatokHD