An equal sign is an assignment operation. == first convert the type and then compare it. === first determine the type. If it is not the same type, it is directly false.
=== Judgment rules
If the types are different, they are [unequal]
If both are numerical values and are the same value, then [equal]; (!Exception) is, if at least one of them is NaN, then [not equal]. (To determine whether a value is NaN, you can only use isNaN() to judge)
If both are strings and the characters at each position are the same, then [equality]; otherwise [not equal].
If both values are true, or both are false, then [equal].
If both values refer to the same object or function, then [equality]; otherwise [not equal].
If both values are null, or both are undefined, then [equal].
== Judgment rules:
If the two value types are the same, make a === comparison.
If the two value types are different, they may be equal. Type conversion is performed according to the following rules and then compared:
If one is null and the other is undefined, then [equal].
If one is a string and the other is a numeric value, convert the string into a numeric value and then compare it.
If either value is true, convert it to 1 and compare; if any value is false, convert it to 0 and compare.
If one is an object and the other is a numeric or string, convert the object into a value of the base type and compare it. Convert an object to a basic type and use its toString or valueOf method. js core built-in class, it will try to valueOf before toString; the exception is Date, which uses toString conversion. Non-JS core object, let's say (it's more troublesome, I don't understand much)
Any other combination is [unequal].
For example:
var a = 9; var b = 9; alert(a == b); alert(a === b);
At this time, the value of alert must be true. Whether it is congruent or equivalent, the reason should be very simple. Just define two variables and assign values, which are of the same type and the values are also equal. However, when a and b both assign an array at the same time, it must be false. This is considered as the address relationship, which must be obvious. Let's give a little summary, hey
Basic types include Undefined, Null, Boolean, Number, and String types, and reference types include arrays, functions, and objects.
1. For basic types such as Number and String, the double equal sign will first convert the types consistently and then compare them. The values and other values are true. When the three equal signs, the types will not be converted. You can directly compare them. Only when both are equal can you be true.
2. For arrays, objects, compare "pointer address" whether it is a double or a three equal sign.
This is the end of this article about briefly discussing the differences between medium-equal signs, double-equal signs and three-equal signs in JavaScript. For more related contents of three equal signs in JavaScript, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!