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

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

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 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