In JavaScript, why typeof null return object?
Why “typeof null” return "object"
console.log(typeof null === "object");
typeof null return "object" is a historical implementation bug. Now we are stuck with it.
null is not a object, because It doesn't have the defining quality of JavaScript objects, namely, it's not a collection of key-and-value pairs; you cannot add properties to null.
/* 2026-06-30 trying to assign a property to null. null is not a object, so it fails. */ try { null.p = 4; } catch (xerror) { console.log(xerror); } // TypeError: Cannot set properties of null (setting 'p')
- The history of “typeof null”
- By Dr Axel Rauschmayer.
- https://2ality.com/2013/10/typeof-null.html
In JavaScript, why typeof null return object?
(ai answer)
In JavaScript, why typeof null return object?
JavaScript null
JavaScript sucks
Spec Reading
- Reading JavaScript spec notes (2015)
- JavaScript Grammar is Not Context-Free (2016)
- JavaScript Syntax Complexity: Lookahead (2015)
- JavaScript sort, is fragile, and most complex, convoluted (2017)
- JavaScript Spec, Term “instance” is Not Defined (2017)
- JavaScript Spec Change on Date Time Zone Default (2022)
- The term INSTANCE in Object Oriented Programing
sucks
- JavaScript Sucks (2017)
- JavaScript is Truly Bad Language (2025)
- JavaScript Sucks. Variations of Looping Thru Array (2025)
- Xah JavaScript Style Guide for FP
- JavaScript, Write All If Statement as If Expression