The difference between the == and === operators in JavaScript

The == operator compares the abstract equality, that is, it performs the necessary type conversions before comparing the equality. The === operator compares strict equality, meaning that it will not perform type conversions.

In JavaScript, the == and === operators are used to compare between two operands.

The == operator abstracts, that is, it makes the necessary type conversions before comparing the equality. Syntax of comparison: a == b .

The === operator compares strict equality, meaning that it will not perform type conversions. So if two values ​​are not of the same type, then when compared, the result will return false. Syntax of comparison: a === b .

Picture 1 of The difference between the == and === operators in JavaScript
The == and === operators in Javascript

Example 1:

 

Output:

 true false 

Example 2:

 

Output:

 true false 

Example 3:

 

Output:

 true false 

In general, the === operator is recommended because it never performs type conversions when making comparisons, so it always produces accurate results.

Readers can learn more about other operators in the article: Operators in JavaScript.

Update 11 February 2020
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile