Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!