I'm having difficulty about 'this' keyword determination.
At creation phase of Execution context, 'this' variable gets created.
And 'this' will be determined by which environmnent its called. it doens't matter how its declared, its determined by how its called right? according to following link, https://javascript.info/object-methods
In JavaScript this is “free”, its value is evaluated at call-time and does not depend on where the method was declared, but rather on what object is “before the dot”.
then can anybody explain following code?
function hey(){
const x = 3;
console.log(this)
}
hey() /// result :: window
I think it should log { x: 3}.
when console.log runs, execution stack will look like this :: [global execution context , hey context]
and since function 'hey' is also object, 'this' should point hey context's variable environment.
but results global environment.
I really don't get this phenomenon.... any ideas about this??
searched for articles, googled, etc..