Can you help me understand this javascript code?

Viewed 26

Can you help me understand this javascript code? Why do we create a function called setGear and write newGear in it and we equate this.gear to newGear? I really didn't understand.

const bicycle = {
  gear: 2,
  setGear(newGear) {
    this.gear = newGear;
  }
};

bicycle.setGear(3);
console.log(bicycle.gear);

0 Answers
Related