javascript - [1] == [1] Is this false or true?
伊谢尔伦
伊谢尔伦 2017-05-19 10:44:27
0
6
1947

[1] == [1] The number of printed values ​​is false. Does anyone know why?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(6)
过去多啦不再A梦

Equality operators among comparison operators are introduced in detail:

Equal(==)

Comparison operators convert two different types of operands and then perform a strict comparison. When both operands are objects, JavaScript compares their internal references and are equal if and only if their references point to the same object (area) in memory, that is, their reference addresses in stack memory are the same.

Everything mentioned above is correct, because in [1] == [1], the two arrays are different objects, so they are not equal.

刘奇

JavaScript中,数组是Object
这一语句通过字面量创建了两个Array, they are different objects, therefore not equal.

阿神

2 Array objects are not the same object.

洪涛

When the compared value is a reference value, it will compare whether the two values ​​are the same object in memory. [1] and [1] here are different, so it is false

習慣沉默

Ecma-262.pdf
7.2.13 Abstract Equality Comparison
已经明确说明了,这里的 [1] = [1] 实际是 [1] === [1] 正好试用第一条。


The comparison x == y, where x and y are values, produces true or false. Such a comparison is performed as follows:

  1. If Type(x) is the same as Type(y), then a. Return the result of performing Strict Equality Comparison x === y.

  2. If x is null and y is undefined, return true.

  3. If x is undefined and y is null, return true.

  4. If Type(x) is Number and Type(y) is String, return the result of the comparison x == ToNumber(y).

  5. If Type(x) is String and Type(y) is Number, return the result of the comparison ToNumber(x) == y.

  6. If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.

  7. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).

  8. If Type(x) is either String, Number, or Symbol and Type(y) is Object, return the result of the comparison x ==
    ToPrimitive(y).

  9. If Type(x) is Object and Type(y) is either String, Number, or Symbol, return the result of the comparison ToPrimitive(x)
    == y.

  10. Return false.

伊谢尔伦

The object type will compare the memory address. If the addresses are different, it is false

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!