The Story behind typeof null returning “object” in Javascript

The Story behind typeof null returning "object" in Javascript


Like in many languages, JavaScript represents objects as references (pointers) to memory locations where the object data is stored. When JavaScript was created, null was represented as a special pointer value that didn’t point to any memory location (a “null pointer”). When the typeof operator was later introduced, it used the same internal mechanism of the JavaScript engine to check the type of values. Since null was represented as a special type of object (a null pointer), the typeof operator returns “object” for null. This behavior, though technically a bug, has not been fixed to maintain JavaScript’s backward compatibility.



Source link
lol

By stp2y

Leave a Reply

Your email address will not be published. Required fields are marked *

No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.