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.
See Question&Answers more detail:osIf 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.
See Question&Answers more detail:osThe 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).