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

(==) - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

(==)

Baseline

20157

(==) 2

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

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

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

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

js
x == y

(== !=) IsLooselyEqual

    • : true
    • : true
    • : true +0 -0 NaN false NaN NaN
    • : true false true
    • : true
    • : true
  1. null undefined null undefined true false
    • 1
    • false
    • true 1 false 0 2
    • : NaN false
    • : Infinity NaN false
    • : 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 ( NOT )
0 == !!undefined; // true ( NOT )
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

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

Date

js
const d = new Date("1995-12-17T03: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` 

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

ECMAScript 2027 LanguageSpecification
# sec-equality-operators


Web Proxy Viewer  |  New URL  |  Original Page