Home  >  Q&A  >  body text

javascript - [1] == [1] Is this false or true?

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

伊谢尔伦伊谢尔伦2710 days ago1973

reply all(6)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-19 10:46:27

    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.

    reply
    0
  • 怪我咯

    怪我咯2017-05-19 10:46:27

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

    reply
    0
  • 阿神

    阿神2017-05-19 10:46:27

    2 Array objects are not the same object.

    reply
    0
  • PHP中文网

    PHP中文网2017-05-19 10:46:27

    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

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-19 10:46:27

    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.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-19 10:46:27

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

    reply
    0
  • Cancelreply