Why null==undefined and null == 0 but undefined!= 0 | Sololearn: Learn to code for FREE!


Why null==undefined and null == 0 but undefined!= 0


5/13/2018 6:59:37 PM


3 Answers

New Answer


JavaScript is weird and funny,lets debug this. null represents an object/variable with no value so its undefined 0 is null since 0 has no value,anything plus 0 is anything so 0 is null. Then 0 is not undefined.Its a valueless number,we know what 0 is,we just dont know its value:: valueless!


== does type coercion, so the value on the left is coerced into the same type as the value on the right. undefined is a state that indicates the programmer forgot to set/define a variable (missing or unset variable). The language has no idea what you mean by whatever you just did. Something fails to exist. null is a state where the programmer deliberately set a value. The language knows what you mean (something exists), but its value is absent. typeof null returning "object" is considered a bug. You may want to read this article for more information: http://2ality.com/2011/03/javascript-values-not-everything-is.html Also in 5. Related content, the link "null is not an object" - comment on Stack Overflow


that is really funny)) only js has null and undefined. in other languages there is only one of them))