Home >Web Front-end >Front-end Q&A >How to convert numbers to string in es6

How to convert numbers to string in es6

青灯夜游
青灯夜游Original
2022-04-19 18:38:163668browse

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()".

How to convert numbers to string in es6

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

How to convert numbers to string in es6

#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

How to convert numbers to string in es6

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

How to convert numbers to string in es6

[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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn