Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
190
rated 0 times [  191] [ 1]  / answers: 1 / hits: 15258  / 11 Years ago, fri, may 17, 2013, 12:00:00

If we alert(null==undefined) it outputs to true.



What is the logical reason for this.



Is this something that is hard coded in javascript or is there an explanation for this.


More From » javascript

 Answers
42

The language specification explicitly says:




If x is null and y is undefined, return true




I'm not aware of any records of the language design process that explain the reasoning for that decision, but == has rules for handling different types, and null and undefined are both things that mean nothing, so having them be equal makes intuitive sense.



(If you don't want type fiddling, use === instead).


[#78164] Thursday, May 16, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
joseluispauld

Total Points: 13
Total Questions: 132
Total Answers: 98

Location: Venezuela
Member since Sat, Apr 24, 2021
3 Years ago
;