0

I know that typeof (null) === "object", but I don't understand why this is acceptable in javascript. According to JavaScript data types and data structures over at MDN, null is a primitive and yet according to their own Glossary;

A primitive (primitive value, primitive data type) is data that is not an object and has no methods. In JavaScript, there are 6 primitive data types: string, number, boolean, null, undefined, symbol (new in ECMAScript 2015).

a primitive must not be an object. I don't understand why this hasn't been fixed in later releases of javascript.

Kyle Richardson
  • 5,567
  • 3
  • 17
  • 40
  • 1
    It's not "fixed" because billions of lines of JavaScript out there depend on the existing behavior. Such "Why is X like Y?" about programming languages are always difficult to really answer, but in this case I suspect the original thinking was that `null` is a value that is used to mean that no object is being referenced. – Pointy Apr 24 '17 at 22:01
  • @Barmar If it's an exact duplicate, why don't you link to the duplicate. – Kyle Richardson Apr 24 '17 at 22:02
  • It **is** linked to the duplicate. – Pointy Apr 24 '17 at 22:03
  • Not for me... because I'd like to see this duplicate question to get my answer. – Kyle Richardson Apr 24 '17 at 22:04
  • @KyleRichardson You don't see the link above the question, or in the **Linked** section of the sidebar? – Barmar Apr 24 '17 at 22:04
  • My apologizes, it was at the top of the screen and i had to scroll up. It was not shown with the closing statement that I was linked to from comment alert. Thank you for the answer. – Kyle Richardson Apr 24 '17 at 22:05
  • @KyleRichardson: yeah, that is a UX fail when related messages are visually separated; forcing to user to have to remember a certain pattern. Don't make me think! – dandavis Apr 24 '17 at 22:40
  • I've never had a question I asked before marked as duplicate. I was unaware that it was even there. Definitely a UX failure. – Kyle Richardson Apr 25 '17 at 01:06

0 Answers0