Home > Article > Web Front-end > Display type conversion in JS
This time I will bring you the display type conversion in JS , what are the precautions for display type conversion in JS, the following is a practical case, let's take a look.
Number(), convert things into numeric types
Number('123'); //123Number('-123'); //-123Number('a'); //NaNNumber(true); //1Number(null); //0Number(undefined); //NaNNumber(NaN); //NaN
parseInt(string, radix), convert strings into integers in the corresponding base system
parseInt('10', 16); //16parseInt('b', 16); //11parseInt('b'); //NaNparseInt('3', 2); //NaN,因为3不是二进制的parseInt(true); //NaNparseInt('123abc'); //123parseInt('abc123'); //NaN
parseFloat(string, radix), convert the string into a floating point number in the corresponding base system
String(mix)
Convert things into string type, undefined and null can be converted into string form
String(null); //"null"String(undefined); //"undefined" toString(radix)
Convert things into string types, undefined and null cannot be used, radix is based on decimal and converted into the target base
var num = 100; num.toString(); // "100"//注意,不能直接123.toString(),会报错
I believe you have mastered the method after reading the case in this article, please come for more exciting information Follow php Chinese websiteOther related articles!
Recommended reading:
Detailed explanation of h5 game development
##The use of Nodejs routing and controller
The above is the detailed content of Display type conversion in JS. For more information, please follow other related articles on the PHP Chinese website!