Javascript equality and equivalence operators are described in detail

  • 2020-03-27 00:11:06
  • OfStack

The == operator and the === operator are used to detect the equality of two values, using two different definitions with the same property. Both of these operators accept any type of operator. If two operators are equal, they both return true. Otherwise, they both return false. The == operator is the equality operator, which USES a looser definition of the same attribute to compare the equality of two operators.

There is a basic understanding of the concept.

So let's say that the two values are equal.

=== operator to compare two values

1. If two values have different types, they are not the same

2, if two values are of type number and have the same value, then they are equivalent unless one or both of them are (NaN) in the middle, which is not the case

3. If two values are strings and the characters at the same position in the string are identical, they are identical. If the length or content of the string is different, they are not identical

The == operator compares two values

1. If the two values are of the same type, their equality is checked. If two values are exactly the same, they are equal. If they're not identical, they're not equal

2. If two values are of different types, they may still be equal (to give a few examples)

1) if one value is null and the other value is undefined, they are equal

2) if one value is a number and the other is a string, convert the string to a number and compare the converted value

3) if a value is true, convert it to 1 and compare. If a value is false, convert it to 0 and compare

4) if one value is an object and the other is a number or string, convert the object to a value of the original type and compare.

Related articles: