I was practicing below code Code Reference : Link
let obj = {
name : "Cj",
sayLater : function(){
setTimeout(function(){
console.log("sayLater :> "+this.name);
},3000)
},
sayNow : function(){
console.log("sayNow :> "+this.name);
},
sayLaterFA : function(){
setTimeout(() => console.log("sayLaterFA :> "+this.name) ,3000)
},
sayNowFA : () => console.log("sayNowFA :> "+this.name),
sayLaterPureFatArrow : () => { setTimeout(() => console.log("sayLaterPureFatArrow :> "+this.name),4000) },
sayNowPureFatArrow : () => { console.log("sayNowPureFatArrow :> "+this.name) }
}
obj.sayLater(); //Output : sayLater :> undefined
obj.sayNow(); //Output : sayNow :> Cj
obj.sayLaterFA(); //Output : sayLaterFA :> Cj
obj.sayNowFA(); //Output : sayNowFA :> Cj
obj.sayLaterPureFatArrow(); //Output : sayLaterPureFatArrow :> undefined
obj.sayNowPureFatArrow(); //Output : sayNowPureFatArrow :> undefined
Can anyone explain me why my output is undefined though I am using fat arrow function