You're developing a Node.js application and notice that the "this" keyword inside a regular function, defined in the global scope, refers to something different than you're used to in client-side JavaScript. What does "this" refer to in this context?

  • It refers to the Node.js global object (e.g., "global" or "window")
  • It refers to the "exports" object
  • It refers to the "module.exports" object
  • It refers to the function itself
In Node.js, when you define a regular function in the global scope (outside any function or module), "this" inside that function refers to the Node.js global object (e.g., "global" in Node.js or "window" in the browser). This behavior is different from client-side JavaScript, where "this" in the global scope refers to the global window object.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *