Home > Mobile >  ECMAScript equality: Is null of Type Object?
ECMAScript equality: Is null of Type Object?

Time:01-03

I am trying to implement the algorithm described in ES262, The Abstract Equality Comparison Algorithm. It states:

  1. If Type(x) is the same as Type(y), then

    a. If Type(x) is Undefined, return true.

    b. If Type(x) is Null, return true.

So when we perform the comparison:

console.log(null == {})

it should evaluate to true, because null and {} have the same type. Do I understand it correctly?

CodePudding user response:

it should evaluate to true because null and {} have the same type and x is null,

This is your mistake.

The types are different.

  • Related