本文介绍了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
相等,对象是比较必须具有相同的类型和:
- 当两个字符串具有相同的序列时,它们严格相等字符,长度相同,相同对应位置的字符.
- 两个数在数值上相等时严格相等(有相同的数值).
NaN
不是等于任何东西,包括NaN
.正负零相等彼此. - 如果两个布尔操作数都为真或为真,则两个布尔操作数严格相等两者都是假的.
- 如果两个对象引用同一个
Object
,则它们严格相等. Null
和Undefined
类型是==
(但不是===
).[IE.(Null==Undefined
) 是true
但 (Null==Undefined
) 是false
]
- Two strings are strictly equal when they have the same sequence ofcharacters, same length, and samecharacters in corresponding positions.
- Two numbers are strictly equal when they are numerically equal (havethe same number value).
NaN
is notequal to anything, includingNaN
.Positive and negative zeros are equalto one another. - Two Boolean operands are strictly equal if both are true orboth 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 中 == 和 === 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!