skip to Main Content

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.

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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 Model

      • https://www.w3schools.com/js/js_window.asp
      • "All global JavaScript objects, functions, and variables automatically become members of the window object."
      • It is a collection of properties and methods that contain information about the browser and computer screen.
      • Even the document object (of the HTML DOM) is a property of the window object.
    • The difference is in the top-level code in a Node module, this is equivalent to module.exports. That’s the empty object you see.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search