Sub-implicit type conversions and explicit type conversions1. Implicit type conversion
+ - * / %
1.1, + more Special:
if there is a string on eitherside of the +, then the+ connection function
+ If both sides are numbers, then the function of the addition operation
1.2,-*/%
when it comes to-*/%, the other types are converted to number types before the corresponding mathematical operations are performed.
2. Explicit type conversions
Number (), parseint (), parsefloat ()
2.1. Number ()
Number () to convert any value to a value
Common conversion instances
varNUM1 = Number (true); varnum2 =Number (undefined); varnum3 = Number (NULL); varNUM4 = number ("Hello"); varNUM5 = Number (""); varNUM6 = number (123); Console.log (NUM1); //returns 1Console.log (NUM2);//return nanConsole.log (NUM3);//returns 0Console.log (NUM4);//return nanConsole.log (NUM5);//returns 0Console.log (NUM6);//back to 123
2.2, parseint ()
Convert a string to an integer
Common conversion instances
varNUM1 = parseint ("12.34abc"); varnum2 = parseint ("abc1234"); varnum3 = parseint (""); varNUM4 = parseint ("100"); varNUM5 = parseint ("0xA"); Console.log (NUM1); //back toConsole.log (NUM2);//return nanConsole.log (NUM3);//return nanConsole.log (NUM4);//returnConsole.log (NUM5);//return ten
2.3, parsefloat ()
varNUM1 = parsefloat ("12.34abc"); varnum2 = parsefloat ("abc1234"); varnum3 = parsefloat (""); varNUM4 = parsefloat ("100"); varNUM5 = parsefloat ("0xA"); Console.log (NUM1); //back to 12.34Console.log (NUM2);//return nanConsole.log (NUM3);//return nanConsole.log (NUM4);//returnConsole.log (NUM5);//returns 0
Parsefloat can only parse ten decimal
Other types of transfer number