Written by
Christopher West (cwest) on
December 06, 2015.
Tests to see if two or more values are exactly the same. This is similar to using "===" except it can be used to differentiate between 0 and -0 and it will correctly indicate that NaN is NaN.
function is(x, y) {
x = x === y
? x !== 0 || 1 / x == 1 / y // -0 vs 0
: (x != x && y != y); // NaN
y = arguments;
return x && y.length > 2
? is.apply(0, slice(y, 1))
: x;
}
is(...) API Documentation
Description
Tests to see if two or more values are exactly the same. This is similar to === with two differences:
-0 === 0 evaluates to true butYourJS.is(-0, 0) evaluates to false
NaN === NaN evaluates to false butYourJS.is(NaN, NaN) evaluates to true
Parameters
x {*}:
The value to be compared to for equality.
y {*}:
The value to compare to x for equality.
...opt_otherValues {...*}:
Optional. If additional values are given they will all be compared to x for equality.
Returns
Returns true if all of the parameters passed in are the same, otherwise false is returned.