Why does typeof null return object?

null is a null pointer object, so is null an instance of Object

var a = null;
typeof a; // object
a instanceof Object // false

null is not an instance of Object, so why is it "objec", is a historical reason or a browser compatibility problem? different browsers will display different answers?

May.08,2022

Why don't you search this question before you ask it? There are a lot of answers.

For more information, please refer to the blogger's answer :

.
  1. null is not a null reference, but an original value, see Section 4.3.11 of the Chinese version of ECMAScript5.1; it just expects that an object will be referenced here, note that it is "expected", refer to null-JavaScript.
  2. typeof null result is object, which is a historical bug, refer to typeof-JavaScript
  3. in ECMA6, there was a proposal to correct the value of type null to null, but the proposal was rejected. The reason is that there is too much code left over from history and do not want to offend people, so it is better to continue to make mistakes and make things old. Refer to harmony:typeof_null [ES Wiki]
  4. .

null is certainly not an instance of Object.
null is an empty object reference, and since it is empty, there are no references. The reason why
typeof a returns Object is because null represents an empty object reference.
typeof a does not have browser compatibility.
there is a practice that if you are going to assign an object to a, then a had better initialize to null instead of undefined.


I suggest you take a look at this URL
idedege/article/details/78659183?locationNum=10&fps=1" rel=" nofollow noreferrer "> https://blog.csdn.net/woshini...

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9e363-19b8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9e363-19b8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?