When I used JavaScript before, I would often encounter the use of the two symbols == and === to determine whether two variables are equal. However, the difference between these two symbols has not been investigated. Today I encountered the === symbol again, so I decided to check what the difference is between the two.
There are two comparison operators "==" and "===" in Javascript, so what is the difference between them?
1. For basic types such as string and number, there is a difference between == and ===
1) Comparison between different types, == compares "values after conversion to the same type" to see if the "values" are equal. === If the types are different, the result will be unequal
2) Same type comparison, direct "value" comparison, the result is the same
2. For advanced types such as Array and Object, there is no difference between == and ===
When a variable is defined as Arrary and a variable is defined as Object type, but their values are the same, the results of == and === comparisons are the same because it is a "pointer address" comparison
3. There is a difference between basic types and advanced types, == and ===
1) For ==, convert the advanced type into a basic type and perform "value" comparison
2) Because the types are different, the result of === is false