Can anyone help me understand the output of the below small es6 program?
I know the difference between arrow function and normal function.
The Arrow function runs in parent's scope. The Normal function runs in its own scope.
PFB the programme that's confusing me.
function Temp(){
this.x =99;
y =88;
var z =77;
setTimeout(function(){console.log(this.y+"::",this.x,"--",this.z),5});
setTimeout(()=>{console.log(this.y+"||",this.x,"--",this.z),5});
doit(function (){ console.log(this.y+":",this.x,"_",this.z);})
doit(()=>{console.log(this.y+"|",this.x,"-",this.z);});
function doit(task){
this.i =0;
task();
}
}
new Temp();
Output
88:: undefined --undefined
undefined|| 99 --undefined
88: undefined -undefined
undefined| 99-undefined
es6 Playground
es6console link Wanted to know the association between variable declaration and function (arrow/normal).