Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda