console.time("Test");
for(var i=0; i
In a web browser(Chrome), declaring the variable i outside of any function scope makes it global and therefore binds to window object. As a result, running this code in a web browser requires repeatedly resolving the property within the heavily populated window namespace in each iteration of the for loop.
In Node.js however, declaring any variable outside of any function’s scope binds it only to the module scope (not the window object) which therefore makes it much easier and faster to resolve.
We will get more or less same execution speed when we wrap the above code in function.