object is
This method was introduced in ES2015. It aims to help comparing values.
ES2015中引入了此方法。 它旨在帮助比较价值。
Usage:
用法:
Object.is(a, b)
The result is always false
unless:
结果始终为false
除非:
a
andb
are the same exact objecta
和b
是相同的精确对象a
andb
are equal strings (strings are equal when composed by the same characters, in the same order)a
和b
是相等的字符串(当由相同的字符以相同的顺序组成时,字符串是相等的)a
andb
are equal numbers (numbers are equal when their value is equal)a
和b
是相等的数字(数值相等时数字相等)a
andb
are bothundefined
, bothnull
, bothNaN
, bothtrue
or bothfalse
a
和b
都undefined
,都为null
,都为NaN
,都为true
或均为false
0
and -0
are different values in JavaScript, so pay attention in this special case (convert all to +0
using the +
unary operator before comparing, for example).
0
和-0
是JavaScript中的不同值,因此请注意这种特殊情况(例如,在进行比较之前,使用+
一元运算符将所有值转换为+0
)。
object is