84669 Lernen von Personen
152542 Lernen von Personen
20005 Lernen von Personen
5487 Lernen von Personen
7821 Lernen von Personen
359900 Lernen von Personen
3350 Lernen von Personen
180660 Lernen von Personen
48569 Lernen von Personen
18603 Lernen von Personen
40936 Lernen von Personen
1549 Lernen von Personen
1183 Lernen von Personen
32909 Lernen von Personen
[1] == [1] Die Anzahl der gedruckten Werte ist falsch. Weiß jemand warum?
小伙看你根骨奇佳,潜力无限,来学PHP伐。
比较操作符中的相等运算符,有详细的介绍:
相等(==) 比较操作符会为两个不同类型的操作数转换类型,然后进行严格比较。当两个操作数都是对象时,JavaScript会比较其内部引用,当且仅当他们的引用指向内存中的相同对象(区域)时才相等,即他们在栈内存中的引用地址相同。
相等(==)
比较操作符会为两个不同类型的操作数转换类型,然后进行严格比较。当两个操作数都是对象时,JavaScript会比较其内部引用,当且仅当他们的引用指向内存中的相同对象(区域)时才相等,即他们在栈内存中的引用地址相同。
楼上说的都对,因为[1] == [1]中,两个数组是不同的对象,所以不相等。
JavaScript中,数组是Object。这一语句通过字面量创建了两个Array,他们是不一样的对象,因此不相等。
JavaScript
Object
Array
2个Array对象不是同一个对象。
当比较的值是引用值时,会比较两个值在内存中是否为同一对象,这里的[1]和[1]不同,所以是false
Ecma-262.pdf7.2.13 Abstract Equality Comparison 已经明确说明了,这里的 [1] = [1] 实际是 [1] === [1] 正好试用第一条。
[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.
对象类型会比较内存地址,地址不同所以为false
比较操作符中的相等运算符,有详细的介绍:
楼上说的都对,因为[1] == [1]中,两个数组是不同的对象,所以不相等。
JavaScript
中,数组是Object
。这一语句通过字面量创建了两个
Array
,他们是不一样的对象,因此不相等。2个Array对象不是同一个对象。
当比较的值是引用值时,会比较两个值在内存中是否为同一对象,这里的[1]和[1]不同,所以是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.
对象类型会比较内存地址,地址不同所以为false