Implicit type conversion steps
First, see whether there is a nan before or after the double equals sign, and return False if there is a Nan.
Second, see whether there is a Boolean before and after the double equals sign, Boolean converts the Boolean to a number. (False is 0,true is 1)
Third, then look at the double equals sign before and after there are no strings, there are three kinds of situations:
1, the other side is the object, the object uses ToString to convert;
2, the other side is the number, the string to the number; (previous examples already)
3, the other side is a string, direct comparison;
4, other return false
Four, if it is a number, the other side is the object, the object takes valueof to compare, the other all return false
Five, null, undefined do not type conversions, but they are both equal
For example to consolidate and improve
Let's do the following topics together!
varA;console.dir (0 = =false);//trueConsole.dir (1 = =true);//trueConsole.dir (2 = = {valueOf:function(){return2}});//trueConsole.dir (A= = NaN);//falseConsole.dir (nan = = Nan);//falseConsole.dir (8 = = undefined);//falseConsole.dir (1 = = undefined);//falseConsole.dir (2 = = {toString:function(){return2}});//trueConsole.dir (undefined==NULL);//trueConsole.dir (NULL= = 1);//falseConsole.dir ({toString:function(){return1}, ValueOf:function(){return[]}} = = 1);//trueConsole.dir (1== "1");//trueConsole.dir (1=== "1");//false
Type conversions caused by JavaScript double equals sign