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.
The above is the detailed content of The Story behind typeof null returning \'object\' in Javascript. For more information, please follow other related articles on the PHP Chinese website!