Home > Web Front-end > JS Tutorial > body text

What is the difference between == and === in js

青灯夜游
Release: 2023-01-05 16:13:43
Original
21743 people have browsed it

Difference: "==" means equal, "====" means strict equality. The "==" operator will perform type conversion of the necessary values ​​before performing an equality comparison; while the "===" operator will not perform type conversion, so if the two value types are different, false will be returned directly during comparison.

What is the difference between == and === in js

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

The difference between == and === in js

Simply put: == represents equality, === represents strict equality, why do you say this?

So Understanding: When comparing double equal signs: First check the data types of the two operands. If they are the same, perform === comparison. If they are different, we are willing to perform a type conversion for you, and then compare them after converting them to the same type. When comparing ===, if the types are different, it is directly false.

Operand 1 == Operand 2, Operand 1 === Operand 2

Comparison process:

Double equal sign==:

 (1) If the two value types are the same, then perform three equal signs Comparison of (===)

 (2) If the two value types are different, they may be equal. Type conversion needs to be performed according to the following rules before comparison:

 1) If one is null, One is undefined, then they are equal

  2) If one is a string and the other is a numerical value, convert the string into a numerical value and then compare it

三EQuous sign====:

 (1) If the types are different, they must not be equal

 (2) If both are numerical values ​​and they are the same value, then they are equal; if at least one of them is NaN, then not equal. (To determine whether a value is NaN, you can only use isNaN() to determine)

  (3) If both are strings and the characters at each position are the same, then they are equal, otherwise they are not equal.

 (4) If both values ​​are true or false, then they are equal

 (5) If both values ​​refer to the same object or function, then they are equal, otherwise they are not Equality

 (6) If both values ​​are null or undefined, then they are equal

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of What is the difference between == and === in js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!