JavaScript中==和===之间的区别 [英] Difference between == and === in JavaScript
本文介绍了JavaScript中==和===之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
之间有什么区别? JavaScript中的==
和 ===
?我还看过!=
和!==
运算符。还有更多这样的经营者吗?
What is the difference between ==
and ===
in JavaScript? I have also seen !=
and !==
operators. Are there more such operators?
推荐答案
===
和!==
是严格的比较运算符:
===
and !==
are strict comparison operators:
JavaScript既有严格也有
类型转换相等比较。
对于strict
相等,
比较的对象必须具有相同的类型并且:
JavaScript has both strict and type-converting equality comparison. For
strict
equality the objects being compared must have the same type and:
- 两个字符串在相应位置具有相同的
字符序列,相同长度和相同的
字符时严格相等。 - 两个数字在数值上相等时严格相等(具有相同数值的
)。NaN
不是
等于任何东西,包括NaN
。
正负零彼此等于
。 - 如果两个布尔操作数均为真,或者两个布尔操作数均为假,则两个布尔操作数严格相等。
- 如果两个对象引用相同的
对象
,则两个对象严格相等。 -
Null
和未定义的
类型是==
(但不是===
)。 [即(Null ==未定义
)是true
但是(Null ===未定义
)false
]
- Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.
- Two numbers are strictly equal when they are numerically equal (have
the same number value).
NaN
is not equal to anything, includingNaN
. Positive and negative zeros are equal to one another. - Two Boolean operands are strictly equal if both are true or both are false.
- Two objects are strictly equal if they refer to the same
Object
. Null
andUndefined
types are==
(but not===
). [I.e. (Null==Undefined
) istrue
but (Null===Undefined
) isfalse
]
这篇关于JavaScript中==和===之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文