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

https://code.sololearn.com/cXy90wtYRrj6/?ref=app

4th Feb 2021, 7:16 PM
جوردن آهو ماولی
جوردن آهو ماولی - avatar
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/
4th Feb 2021, 7:39 PM
visph
visph - avatar
+ 1
visph thanks so much bro ☺️ ☺️ ☺️ ☺️ ☺️
4th Feb 2021, 8:02 PM
جوردن آهو ماولی
جوردن آهو ماولی - avatar
0
On chrome console, it works as expected. But it gives undefined on sololearn!
4th Feb 2021, 7:25 PM
جوردن آهو ماولی
جوردن آهو ماولی - avatar
0
I'll post the chrome results on my status
4th Feb 2021, 7:26 PM
جوردن آهو ماولی
جوردن آهو ماولی - avatar