简体   繁体   中英

ECMAScript equality: Is null of Type Object?

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?

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

This is your mistake.

The types are different.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM