Why type of null is object?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

Why type of null is object??

Null = Noting, then why typeOf(null) is 'object'?? https://code.sololearn.com/WE154SIWyB8g/?ref=app

8th Apr 2019, 5:14 AM
Ayan Fox
Ayan Fox - avatar
8 Answers
+ 8
null is a primitive type in JavaScript but typeof null returns object, this is a bug in JavaScript language which existed from first version of JavaScript. This bug cannot be fixed because it would break existing code.
8th Apr 2019, 9:37 AM
VEDANG
VEDANG - avatar
+ 8
You have declared obj as the type of null. Since, null is an object, you are getting object as the answer. And there is not types of null. Null is actually an object.
8th Apr 2019, 7:28 AM
Arushi Singhania
Arushi Singhania - avatar
+ 6
You mean is Null of type Object? Then yes.
9th Apr 2019, 1:15 PM
Sonic
Sonic - avatar
+ 3
& yes, I havn't declared the type of 'obj' (in the code). Then why it works??
8th Apr 2019, 5:20 AM
Ayan Fox
Ayan Fox - avatar
+ 2
Because 0 is still a bit.
11th Apr 2019, 8:23 AM
Travis J. Hood
Travis J. Hood - avatar
+ 1
every element that take space is object so when we declare the null it takes space.
9th Apr 2019, 5:12 AM
Negar Yousufzai
Negar Yousufzai - avatar
+ 1
if null is nothing then why it takes space?
9th Apr 2019, 5:44 PM
Azhar Ul Islam 🇵🇰
Azhar Ul Islam 🇵🇰 - avatar
+ 1
Travis this is the simplest, yet the most comprehensive answer I ever got in any question. ++ for you
11th Apr 2019, 10:10 AM
Azhar Ul Islam 🇵🇰
Azhar Ul Islam 🇵🇰 - avatar