DEV Community

Discussion on: Tricky JavaScript Questions

Collapse
 
eladh profile image
Elad Hirsch

10x mate :-) , it's always important to refresh the basics.
In Q8 - Running the code in Node will result undefined , see more details :
stackoverflow.com/questions/602986...

Collapse
 
tomeraitz profile image
Tomer Raitz

Thank you for the response. It's is very helpful. You right, The window object exists only in the browser (client-side). I wanted to show the basic concepts of javascript. The scope of node js it's a little bit different. You can create a global variable by doing global.length (not recommended) - but without it, I think this won't know what length is. if you that in node.js it will work:

global.length = 10;
function fn () {
  console.log (this.length);
}
fn();
Enter fullscreen mode Exit fullscreen mode