The this Keyword

PHOTO EMBED

Thu Jul 21 2022 04:05:27 GMT+0000 (Coordinated Universal Time)

Saved by @cruz #javascript

const robot = {
  model: '1E78V2',
  energyLevel: 100,
  provideInfo() { 
    return `I am ${this.model} and my current energy level is ${this.energyLevel}.`
  }
};

console.log(robot.provideInfo());

///.this with method


const robot = {
  energyLevel: 100,
  checkEnergy() {
    console.log(`Energy is currently at ${this.energyLevel}%.`)
  }
}

robot.checkEnergy();
content_copyCOPY