Home > Article > Web Front-end > Detailed explanation of the difference between == and === in js
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!