1. Convert other data types to number type
Number (), strict
Parsefloat/parseint-Not strict
1) Convert the Boolean type to a number true->1 false->0
2) Convert null/undefined to digital null->0 Undefined->nan 10+null=10 10+undefined=nan
3) Convert [] to a number first call the array's ToString method to put []-> "", and then use the numbers method to put "" "->0
2. Convert other data types to Boolean types
Only 0, NaN, null, Undefined, "" These five are converted to Boolean types when false, the rest of the conversion is true
3, two values to compare, if the left and right side of the data type is different, we need to follow a set of rules for the default data type conversion
1) Object = = Object compares the memory address stored by itself, not equal if the memory address is different []==[]->false each empty array is a separate memory address
2) Object = = String called the ToString method to convert the object to a string []== ""->true
3) Object = = Boolean convert to Number (Tostring-number), and Boolean to number (true->1 false->0)
[]==false->true []->0 false->0 0==0->true
! []==false! [] First convert an empty array to a Boolean type and then take the inverse->false false==false->true
4) Object = = Number object converted to digital []==0->true []==1->false
5) String = = Boolean both converted to the number "3" ==true->false "1" ==true->true
6) String = = number String converted to number "" ==0->true
7) Boolean = = Numeric Boolean converted to digital true==1->true True==2->false
8) null==undefined->true null===undefined->false
Null/undefined and any other values are not equal null==0->false
9) Nan==nan->false NaN and any values (including yourself) are not equal
Data type conversions in JavaScript