I have the following code
const name = 'Jordan'
const myObj = {
getName: function() {
return this.name
},
getNameAnonymous: () => {
return this.name
}
}
console.log(myObj.getName())
console.log(myObj.getNameAnonymous())
When running, getName returns undefined and getNameAnonymous returns "result" (when I run it in JSFiddle but when I run it with Node I get undefined)
From what I understand this inside of arrow functions inside of objects is bound to the parent scope, so why doesn't getNameAnonymous return Jordan? And why does getName return undefined instead of a ReferenceError?