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

229
Visualizações
Why is the .__proto__ of the base object in Javascript null instead of undefined?
var a = {};
console.log(a.__proto__); // shows the base object
console.log(a.__proto__.__proto__); // shows the prototype of the base object as "null". 

Why isn't it undefined (as it is never declared as a property in the base object)?

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

0

null indicates an intentional absence of a value, typically of an object value. From the spec:

null value

primitive value that represents the intentional absence of any object value

In contrast, for undefined it says:

undefined value

primitive value used when a variable has not been assigned a value

Object.prototype's prototype is intentionlly set to indicate that there's no prototype, and separately prototype objects are, well, objects, so null for "no object" makes the most sense.


That said, beware of "why" questions with JavaScript, because although most of them have perfectly reasonable explanations, some of the most odd things just come down to "Because that's what Brendan Eich thought he should do at the time" and/or "Because there was a bug in the original implementation that got copied by other implementations and couldn't be changed without breaking existing code, so it had to be put in the spec." (For instance, that's why typeof null is "object" rather than "null".) I'm not saying don't ask "why" questions, because again, often there's a good reason that can lead to a better understanding of the language. Just beware that sometimes, well, there just isn't.😀

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