[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/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 ..

(==) , , . .

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

(== !=) IsLooselyEqual. :

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

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

(===) , . . , , 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,      
0 == !!undefined; // true,      
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

, , new 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

js
const d = new Date("1995-12-17T03:24:00");
const s = d.toString(); // : "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

Specification
ECMAScript 2027 LanguageSpecification
# sec-equality-operators


Web Proxy Viewer  |  New URL  |  Original Page