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

Detailed explanation of the difference between == and === in js

高洛峰
Release: 2017-01-10 11:41:28
Original
1312 people have browsed it

In order to reduce conceptual confusion, = should be called (get or assign), == should be called (equal), === should be called (strict equal)

Same points:

Both of their operators allow operands of any type. If the operands are equal, return true, otherwise return false

Different:

==: The operator is called equality, used To detect whether two operands are equal. The definition of equality here is very loose and can allow type conversion

===: used to detect whether two operands are strictly equal

1, For basic types such as string and number, there is a difference between == and ===

Comparison between different types, == compares the "value converted to the same type" to see whether the "values" are equal, = ==If the types are different, the result will be unequal

Same type comparison, direct "value" comparison, the result will be the same

2. For advanced types such as Array, Object, == There is no difference between === and ===

3. Basic types and advanced types, there is a difference between == and ===

For ==, convert the advanced type into a basic type and perform "Value" comparison

Because the types are different, the === result is false

The above is the entire content of this article. I hope that the content of this article can bring some help to everyone's study or work. At the same time, I also hope to support the PHP Chinese website!

For more detailed explanations of the difference between == and === in js, please pay attention to 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!