Quick actions

cmd+k|ctrl+k

Navigation

Languages

Lexical and the this Keyword

Snippet info

Language

JavaScript

Visibility

public

Author

sanjivrai543

Created

2020-10-27T23:27:54Z

Updated

2020-10-27T23:27:54Z

console.log("Hello World!");
/*const person={name:'Alex',
    cars:['ferrari','alto'],
    toString:()=>{console.log(`${name} has ${cars}`);}
}
person.toString();
*/
//the use of this
//cant use arrow function here wont work
const person={
    name:'Alex',
    cars:['ferrari','alto'],
 //   toString:function(){console.log(`${this.name} has ${this.cars}`)}
 toString:function(){

this.cars.forEach((car)=>{console.log(`${this.name} has ${this.car}`)});
//that.cars
}}
//console.log(person);
person.toString();
//will work for es6









INFO