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

163
Visualizações
Is `this` a keyword or a literal?

Why JS specs call this a keyword and not a literal?

It more seems to be a literal, because we can use it as a value, or what am I missing?

return this

What is it then?

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

0

It doesn't really matter, but it's a keyword according to the specification: See Keywords and Reserved Words and Literals. The spec also uses the phrase "keyword this" in the text a fair bit, for instance (picking an instance at random), there's this text in the section on the abstract GetThisEnvironment operation:

...It determines the binding of the keyword this using the LexicalEnvironment of the running execution context...

Earlier versions of the specification were quite explicit about it:

[From The ECMAScript 2019 Language specification]

11.6.2.1 Keywords

The following tokens are ECMAScript keywords and may not be used as Identifiers in ECMAScript programs.

Syntax

Keyword :: one of    await break case catch class const continue debugger default delete do else export extends finally for function if import in instanceof new return super switch this throw try typeof var void while with yield

(My emphasis.)

Continuing with your question:

It more seems to be a literal, because we can use it as a value...

I don't think there's any conflict between something being a keyword and producing a value when used in an expression. this is a keyword you can use to access the value of the ThisBinding of the environment record for the current execution context (or the nearest one that has one).

rici made a really good point in the comments: They said they don't think of this as a literal because unlike (say) true and false, it doesn't have a fixed value. Literals always have the same value, "a" is always "a", true is always true, null is always null, etc. But this has different values in different places in the code. It really acts more like a const than a literal; an implicit const set in the scope's environment object (or not, in the case of arrow function scope).

But again: It really doesn't matter. It's a reserved word that has a special purpose and function in the language, which seems sufficient that we needn't worry about whether it's a keyword or a literal (or both). :-)

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