470,564 Members | 2,293 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,564 developers. It's quick & easy.

Why null==undefined is true in javascript?

84 64KB
Why null==undefined is true in javascript?
Jul 29 '20 #1
2 4180
9,065 Expert Mod 8TB
Because you are using the abstract equality operator (==) which allows the interpreter to coerce the types on either side of the comparison. Not sure which way it is trying to do it, either null is coerced into undefined (the type) or undefined is coerced into (object (the type of null)); I suspect the former. However once the coercion has happened the resulting values of the 2 sides are the same.

If you used the script equality operator (===) then the types have to be the same since the type of null is object and the type of undefined is undefined the operator will return false.
Jul 29 '20 #2
62 32bit
== has rules for managing different types, and "null" and "undefined" are both things that mean "nothing," so having them be equal makes intuitive sense.
Aug 6 '20 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by J de Boyne Pollard | last post: by
5 posts views Thread by =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?= | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.