When I log (this) in the browser I get window Object, But when I log (this) in node.js I got {}.
I road global object in node js is same window object in browser, What is precisely the deference between this and global Object in Node.js?
Thanks for your answers.
Question posted in Javascript
A very good W3school tutorial can be found here.
A very good W3school tutorial can be found here.
2
Answers
Node.js is capable of printing objects without the need to convert them into strings in the console log, while i am guessing in the browser that is not possible. "{}" is an empty object in javascript
Simple answer to me seems to be, in both examples
this
is the global object for the JavaScript runtime.In the browser,
this
is the Browser Object ModelThe difference is in the top-level code in a Node module,
this
is equivalent tomodule.exports
. That’s the empty object you see.jsdom
in Node.js to get access to the APIs used in a browser DOM https://www.npmjs.com/package/jsdom