Another topic on arrow functions
and this value but I can't find the answer to the code that confuses me.
When I run this code in the browser's console the result is true:
var f = () => { return this; };
f() === window; // true
f() // Window
But when I run the same code in Node I get different result:
var f = () => { return this; };
console.log(f() === global); // false
console.log(f() === undefined); // false
console.log(f()); // {}
Also when an object is defined:
let button = {
isClicked: false,
click: () => { this.isClicked = true }
}
console.log(button.isClicked); // false
button.click();
console.log(button.isClicked); // false
When this line is executed in Node the result is undefined:
console.log(global.isClicked); // undefined
But when executed in browser, the result is true:
console.log(window.isClicked); // true
Why when the code is executed in the browser this refers to window object but when executed in Node this does not refer to global ?