0
Why undefined? The foo was called in the global and so the this has a binding to the global. It has to output 5
4 odpowiedzi
+ 2
in nodejs, global object is slightly different from window object (in browsers).
in nodejs, there is a file scope: this is were reside var/let/const declared variables.
in browsers, there's no file scope.
var/let/const reside on global scope, wich is the window object (default this value on non "strict mode" until function used as method -- then this is the object).
in nodejs, global scope is also reachable by this (or 'global' identifier), but that's not the namespace of the file scope variable.
https://stackabuse.com/using-global-variables-in-node-js/
+ 1
visph thanks so much bro ☺️ ☺️ ☺️ ☺️ ☺️
0
On chrome console, it works as expected. But it gives undefined on sololearn!
0
I'll post the chrome results on my status