[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/Equality [Back]  [Original]

(==) - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

(==)

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

(==) , . .

In this article

console.log(1 == 1);
// Expected output: true

console.log("hello" == "hello");
// Expected output: true

console.log("1" == 1);
// Expected output: true

console.log(0 == false);
// Expected output: true

js
x == y

(== !=) . .

  1. .
    • : true .
    • : true .
    • : true . +0 -0 . NaN false . NaN NaN .
    • : true false true .
    • BigInt: true .
    • : true .
  2. null undefined , true null undefined . false .
  3. , .
  4. , (, , , , BigInt ) . .
    • , 1 .
    • , false .
    • , . true 1 false 0 . .
    • : . NaN, false .
    • BigInt: . Infinity NaN false .
    • BigInt: BigInt() BigInt . false .

. A B A == B B == A ( ).

(===) . . 1 false .

" " . document.all , undefined . document.all == null true, document.all === undefined && document.all === null false .

js
1 == 1; // true
"hello" == "hello"; // true

js
"1" == 1; // true
1 == "1"; // true
0 == false; // true
0 == null; // false
0 == undefined; // false
0 == !!null; // true, look at Logical NOT operator
0 == !!undefined; // true, look at Logical NOT operator
null == undefined; // true

const number1 = new Number(3);
const number2 = new Number(3);
number1 == 3; // true
number1 == number2; // false

js
const object1 = {
  key: "value",
};

const object2 = {
  key: "value",
};

console.log(object1 == object2); // false
console.log(object1 == object1); // true

String String objects

new String() . , String . String , .

js
const string1 = "hello";
const string2 = String("hello");
const string3 = new String("hello");
const string4 = new String("hello");

console.log(string1 == string2); // true
console.log(string1 == string3); // true
console.log(string2 == string3); // true
console.log(string3 == string4); // false
console.log(string4 == string4); // true

Dates

js
const d = new Date("December 17, 1995 03:24:00");
const s = d.toString(); // for example: "Sun Dec 17 1995 03:24:00 GMT-0800 (Pacific Standard Time)"
console.log(d == s); //true

js
const a = [1, 2, 3];
const b = "1,2,3";
a == b; // true, `a` converts to string

const c = [true, 0.5, "hey"];
const d = c.toString(); // "true,0.5,hey"
c == d; // true

Specification
ECMAScript 2027 LanguageSpecification
# sec-equality-operators

See also


Web Proxy Viewer  |  New URL  |  Original Page