I am new to Javascript, please help me in understanding the significance of "this" keyword.
I have added comments in front of each console.log()
statements in below code snippet, these are my questions/doubts.
This is my code :
var parentObj = {
aa : 87,
bb : 11,
childObj : {
a : 12,
b : 1122,
fun1 : function(){console.log(this)}, // this is method() so here "this" will point to our "childObj"
fun2 : ()=>{console.log(this)}, //this Fat Arrow function is pointing to "window(global)" object why?
fun3 : function(){
var innerFunc1 = ()=>{ console.log(this)} // this Fat Arrow function is pointing to "childObj" object why?
innerFunc1();
function innerFunc2(){console.log(this)} // this regular function is pointing to "window(global)" object why?
innerFunc2()
}
}
}
parentObj.childObj.fun1();
parentObj.childObj.fun2();
parentObj.childObj.fun3();
This is the OutPut I am getting :