0

We all know that type of null is object and type of undefined is undefined. I would like to know how it returns true for null == undefined and returns false for null === undefined

null == undefined // true
null === undefined // false
  • 3
    Because the spec explicitly says it is. – Pointy Aug 26 '19 at 16:23
  • 4
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#Loose_equality_using – Calvin Nunes Aug 26 '19 at 16:23
  • When you use `==`, the objects are converted to the same type and then compared. That's the difference between `==` and `===`. – Barmar Aug 26 '19 at 16:25
  • Because `==` is designed to say that two things are equal if they are "more or less equal", according to some heuristics. This tends to cause more problems than it solves, which is why you should always use strict equality, `===`. – MultiplyByZer0 Aug 26 '19 at 16:25

0 Answers0