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

114
Visualizações
JavaScript this referring to global object in strict mode

I was learning this in JavaScript and according to my understanding inside strict mode this should be undefined but when I try this

"use strict";


function demo () {
    // Here this is Undefined in strict mode
    console.log(this);
}

//Here this refers to the Global Object
console.log(this);

demo();

As mentioned in the comment, console still prints the Window Object except when I call the demo() object. Why is that so?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

ECMA2015 (ES6) specified that global environment records supply a this value:

8.1.1.4.8 HasThisBinding () Global Environment Records always provide a this binding whose value is the associated global object.

By ECMA2018,this was modified slightly - from table 17 in section 8.1.1.4 Global Environment Records of this edition:

Table 17: Additional Fields of Global Environment Records
...
Field Name: [[GlobalThisValue]]
Value: Object
Meaning: Object The value returned by this in global scope. Hosts may provide any ECMAScript Object Value.

However typical host environments still set the global this value to the global object and I assume will continue to do so.

While strict mode does provide that the this value in an function called simply and directly to be undefined, it does not suppress the creation of a binding for this in the global environment record which will be seen as the this value in global, file-level code.

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