The difference and difference between == and === in JavaScript.

1、 ‘==’
  • First check whether the data types of the two operands are the same
  • If they are the same, compare the two numbers for equality
  • If they are different, first convert the two numbers to the same data type, and then compare
  • '==' Only judge the results on both sides of the equal sign, for example: 1 == '1' (compare number 1 with string 1) and the result is true.
2、 ‘===’
  • First check whether the data types of the two operands are the same
  • If different, return false directly
  • If they are the same, compare whether they are equal
  • '===' First judge the data types on the left and right sides. If the data types are inconsistent, return false directly, and then judge the values ​​on both sides. For example: 1 === '1' (compare number 1 with string 1) the result is false.
Extended knowledge:
null==undefined //true
null===undefined //false
NaN==NaN //false
NaN===NaN //false
NaN不与任何相等,包括自己本身。

Guess you like

Origin blog.csdn.net/ni15534789894/article/details/111467826