Skip to content

PRO TIP Block youtube.com at the DNS level โ€” Pi-hole, NextDNS or your hosts file โ€” but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

What is THIS in JavaScript? ๐Ÿ‘ˆ

60.8K views on YouTube

#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();