null is a primitive but typeof(null) return “object” Reason? In short: it is bug in ECMAScript, and the type should be null. This is a official mistake in the language, carefully kept from 90’s for compatibility. Examples:
1 2 3 4 5 6 7 8 9 10 11 |
typeof null // object typeof undefined // undefined typeof Boolean // Boolean typeof Number // number typeof String // string typeof Object // object typeof NaN // number typeof true // boolean typeof [] // object typeof new Date // object typeof new String(“test”) // object |
How weRead more…