Conversion method: 1. Use " " to splice a null character into the number, the syntax is "number"""; 2. Use String() to convert the value of the object into a string, the syntax is "String(number Object)"; 3. Use toString() to return the string representation of the number, the syntax is "number.toString()".
The operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.
es6 Method of converting numbers to strings
1. Splice a null character into the number
var a = 1+""; alert(typeof a); //string
#2. Use the String method
String() function to convert the value of the object into a string.
var a = 1; console.log(typeof a);//number var b = String(a); console.log(typeof b); //string
3. Use toString() method
toString() method can convert numbers into strings and return numbers. String representation.
var a = 1; console.log(typeof a);//number var b = a.toString(); console.log(typeof b); //string
[Related recommendations: javascript video tutorial, web front-end】
The above is the detailed content of How to convert numbers to string in es6. For more information, please follow other related articles on the PHP Chinese website!