The use of 'this' keyword in JavaScript (very basic question...)
what's the difference between these? //1. No use of 'this.' let person = { firstName: `Ryan`, lastName: `Christiani`, sayName() { return `Hi my name is ${person.firstName} ${person.lastName}`; } }; console.log(person.sayName()) //2. Using 'this.' let person = { firstName: `Ryan`, lastName: `Christiani`, sayName() { return `Hi my name is ${this.firstName} ${this.lastName}`; } }; console.log(person.sayName()) // the results were same, but should I use 'this.' ? those codes are from https://css-tricks.com/template-literals/ the second one is original codes. there's some reason to use this. ? which is better? https://www.w3schools.com/js/js_this.asp " The JavaScript this keyword refers to the object it belongs to. In an object method, this refers to the "owner" of the method. " so, I guess, the 'sayName()' method is inside the object 'person', so I should use 'this.firstname'? If I use 'person.firstname' then it is kind of unnecessary overlapping or something like that? thank you in advance