Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda