JavaScript Hacks: Why console.log(typeof null) returns 'object'

JavaScript Hacks - 😶🌫️ console.log(typeof null) still breaks smart developers in interviews. The output is "object". This confuses people because null is not an object. → JavaScript stores type info using internal tags, and null was given the same tag as objects in the first version of the language. → That decision shipped in 1995, and changing it now would break millions of websites. → The ECMAScript spec keeps this behavior for backward compatibility, even though it is wrong. → null is a primitive value that represents intentional absence, not a data structure. #javascript #frontend #hacks #interviewpreparation

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories