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.
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
Equality operators among comparison operators are introduced in detail:
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:
If Type(x) is the same as Type(y), then a. Return the result of performing Strict Equality Comparison x === y.
If x is null and y is undefined, return true.
If x is undefined and y is null, return true.
If Type(x) is Number and Type(y) is String, return the result of the comparison x == ToNumber(y).
If Type(x) is String and Type(y) is Number, return the result of the comparison ToNumber(x) == y.
If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).
If Type(x) is either String, Number, or Symbol and Type(y) is Object, return the result of the comparison x ==
ToPrimitive(y).
If Type(x) is Object and Type(y) is either String, Number, or Symbol, return the result of the comparison ToPrimitive(x)
== y.
Return false.
The object type will compare the memory address. If the addresses are different, it is false