garyfitz
3/22/2018 - 7:30 AM

.this keyword example

We need to use this to be able to use variables in the local scope of the object

//Objects

//keyword this
//Object example
let user = {
  name: 'Gary',
  lastName: 'Fitzwater',
  age: 50,
  cars: ['BMW', 'Audi'],
  misc: {
    hobbies: ['skating', 'boxing'],
    lang: 'arabic'
  },
  salute: function(){
    console.log(`Hi there I am ${this.name} I am ${this.age} years old`);
  }
};

user.salute();