Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
Same code but different output of 'this' for VS Code and browser console

I have executed the following code both in VS Code and browser console

var message = 'I am your teacher'

function executeWorkshop(greeting){
  return function ask(){
    console.log(`${greeting}, ${this.message}`);
  }
}

executeWorkshop("Hi")();

Outputs

VS Code:

Hi, undefined

Browser:

Hi, I am your teacher
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For web browsers, we have a window object. It provides the browser window functionality and also plays the role of a global object. When scripts create global variables in the web browsers, they're created as members of the global object(window object).

In Node.js, This is not the case. NodeJs has something called global object.

Here are some facts:

  • In the Node.js module system, each file is treated as a separate module.
  • The Global objects are available in all modules.
  • While in browsers, the global scope is the window object, in nodeJS, the global scope of a module is the module itself, so when you define a variable in the global scope of your Node.js module, it will be local to this module.

NodeJs: On NodeJs

Browser: On Browser

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!