等号(=)と3つの等号および2つの等号(「===」および「==」)の違い



Difference Between An Equal Sign



  • 等号(=)は、変数に1を割り当てることを意味します
  • ==:これは等価文字と呼ばれます。等号の両側のタイプが同じである場合、値は等しいかどうか直接比較されます。それらが同じでない場合、それらは最初に同じタイプに変換されてから比較されます
  • ===:それは(一定の等しい)同等性と呼ばれます。両側のタイプが同じである場合、値は直接比較されます。タイプが同じでない場合、falseが直接返されます
Type conversion rules: 1) If the two sides of the equal sign are any two of boolean, string, and number for comparison, they are converted into numbers for comparison. 2) If null or undefined appears on both sides of the equal sign, null and undefined are equal to each other except for being equal to themselves

注:NaN == NaN // falseを返し、NaNとそれ自体を含むすべての値が等しくありません。
————————————————
==は最初に型を変換してから比較し、===は最初に型を比較します。型が異なる場合は、不等式を直接返します。