On the difference between '==' and '===' in Javascript

  • 2020-05-07 19:16:37
  • OfStack

When we used JavaScript before, from time to time we used the symbols == and === to determine whether two variables are equal. But the difference between the two symbols was not investigated. Today, I encountered the symbol === again, so I decided to look up the difference between the two.

There are "==" and "===" in Javascript, so what's the difference?

1. For basic types like string and number, there is a difference between == and ===

1) comparison between different types, == comparison "converted to the value of the same type" to see whether the "value" is equal, === if the type is different, the result is not equal
2) compare with the type, and directly make a "value" comparison, and the two results are 1

2. For advanced types like Array and Object, there is no difference between == and ===

When 1 variable is defined as Arrary and 1 variable is defined as Object, but with the same value, the result of the == and === comparison is the same, because it is a "pointer address" comparison

3. Basic types are different from advanced types, == and ===

1) for ==, convert the advanced to the base type and make a "value" comparison
2) because of different types, === the result is false


Related articles: