I am following along with a tutorial about this
and execution context. I observed that this code executes properly in the Chrome Console:
var globalThis = this
function myFunc () {
console.log('globalThis: ', globalThis)
console.log('this inside: ', this)
console.log(globalThis === this)
}
myFunc()
// globalThis: Window {...}
// this inside: Window {...}
// true
However, when I try to execute this same code in a node environment, I get this as a response:
globalThis: {}
this inside: { console: [Getter],
global: [Circular],
process:
process {
title: 'node',
version: 'v8.16.2',
...
false
I understand that the global node this
value should be different from the browser javascript this
value, but the question is, why does myFunc's this
value not equal the global value?