| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Guide/Equality_comparisons_and_sameness | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
JavaScript .
=== - ( )== - ( )Object.is(). .
==) , IEEE 754 NaN, -0, +0 ( NaN != NaN -0 == +0).===) (NaN, -0, +0 ) . false .Object.is() NaN, -0, +0 ( === ).JavaScript 4 3 .
=====Object.is() . . , x y , false .
. . , . . , NaN , +0 -0 .
const num = 0;
const obj = new String("0");
const str = "0";
console.log(num === num); // true
console.log(obj === obj); // true
console.log(str === str); // true
console.log(num === obj); // false
console.log(num === str); // false
console.log(obj === str); // false
console.log(null === undefined); // false
console.log(obj === null); // false
console.log(obj === undefined); // false
. " " . . 0 . , +0 -0 . NaN (: ) . NaN . ((x !== x) true x NaN .)
=== Array.prototype.indexOf(), Array.prototype.lastIndexOf(), TypedArray.prototype.indexOf(), TypedArray.prototype.lastIndexOf(), case . , indexOf(NaN) NaN NaN switch case .
console.log([NaN].indexOf(NaN)); // -1
switch (NaN) {
case NaN:
console.log("Surprise"); // .
}
. , A == B A B B == A ( ). == .
true .true .true . +0 -0 . NaN false . NaN NaN .true false true .true .true .null undefined true null undefined . false .false .true 1 false 0 . .NaN false .NaN false .BigInt() BigInt . false ., ECMAScript undefined null . ( document.all ) undefined . . null == A undefined == A A undefined true . undefined null .
. , .
0, bigint 0n, '0', toString() '0' .
const num = 0;
const big = 0n;
const str = "0";
const obj = new String("0");
console.log(num == str); // true
console.log(big == num); // true
console.log(str == big); // true
console.log(num == obj); // true
console.log(big == obj); // true
console.log(str == obj); // true
== .
. ( Liskov .) .
// NEGATIVE_ZERO Number .
Object.defineProperty(Number, "NEGATIVE_ZERO", {
value: -0,
writable: false,
configurable: false,
enumerable: false,
});
function attemptMutation(v) {
Object.defineProperty(Number, "NEGATIVE_ZERO", { value: v });
}
Object.defineProperty , . v -0 , . , .
Object.is . ID .
, +0 -0 .
JavaScript API , .
function sameValueZero(x, y) {
if (typeof x === "number" && typeof y === "number") {
// x y (-0 0 ) NaN.
return x === y || (x !== x && y !== y);
}
return x === y;
}
NaN , -0 0 . NaN , . Array.prototype.includes(), TypedArray.prototype.includes(), Map Set .
"" . , . (: 6 == "6"). . .
" " , " " 1 "" . Object.is , "" , "" (, ). Object.is NaN . Object.is(NaN, NaN) false Object.is -0 +0 / . NaN . Object.is .
| x | y | == |
=== |
Object.is |
SameValueZero |
|---|---|---|---|---|---|
undefined |
undefined |
true |
true |
true |
true |
null |
null |
true |
true |
true |
true |
true |
true |
true |
true |
true |
true |
false |
false |
true |
true |
true |
true |
'foo' |
'foo' |
true |
true |
true |
true |
0 |
0 |
true |
true |
true |
true |
+0 |
-0 |
true |
true |
false |
true |
+0 |
0 |
true |
true |
true |
true |
-0 |
0 |
true |
true |
false |
true |
0n |
-0n |
true |
true |
true |
true |
0 |
false |
true |
false |
false |
false |
"" |
false |
true |
false |
false |
false |
"" |
0 |
true |
false |
false |
false |
'0' |
0 |
true |
false |
false |
false |
'17' |
17 |
true |
false |
false |
false |
[1, 2] |
'1,2' |
true |
false |
false |
false |
new String('foo') |
'foo' |
true |
false |
false |
false |
null |
undefined |
true |
false |
false |
false |
null |
false |
false |
false |
false |
false |
undefined |
false |
false |
false |
false |
false |
{ foo: 'bar' } |
{ foo: 'bar' } |
false |
false |
false |
false |
new String('foo') |
new String('foo') |
false |
false |
false |
false |
0 |
null |
false |
false |
false |
false |
0 |
NaN |
false |
false |
false |
false |
'foo' |
NaN |
false |
false |
false |
false |
NaN |
NaN |
false |
false |
true |
true |
0 Object.is , Object.defineProperty . , Object.is === . NaN true , NaN ( ECMAScript isNaN ) 0 .
-0 +0 .
- ( ).
const stoppingForce = obj.mass * -obj.velocity;
obj.velocity 0( 0 ) -0 stopsingForce .
Math.atan2, Math.ceil, Math.pow, Math.roundMath.floor, Math.max, Math.min, Math.sin, Math.sqrt, Math.tan-0 -0 . Math.min(-0, +0) -0 . , .
~, <<, >> ToInt32 . 32 0 -0 . , Object.is(~~(-0), -0) Object.is(-0 << 2 >> 2, -0) false .
0 Object.is . -0 +0 .
const f2b = (x) => new Uint8Array(new Float64Array([x]).buffer);
const b2f = (x) => new Float64Array(x.buffer)[0];
// NaN .
const n = f2b(NaN);
// NaN .
n[0] = 1;
const nan2 = b2f(n);
console.log(nan2); // NaN
console.log(Object.is(nan2, NaN)); // true
console.log(f2b(NaN)); // Uint8Array(8) [0, 0, 0, 0, 0, 0, 248, 127]
console.log(f2b(nan2)); // Uint8Array(8) [1, 0, 0, 0, 0, 0, 248, 127]
This page was last modified on 2025 6 27 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |