Home > Web Front-end > JS Tutorial > body text

What is the function in js that converts a number into the corresponding string?

青灯夜游
Release: 2022-12-30 11:13:32
Original
8898 people have browsed it

In JavaScript, the function that converts a number into the corresponding string is "toString()". toString() can convert a Number object into a string and return the result; the syntax format is "Number object.toString()".

What is the function in js that converts a number into the corresponding string?

The operating environment of this tutorial: Windows 7 system, ECMAScript version 5, Dell G3 computer.

In JavaScript, you can use the toString() function to convert a number into a corresponding string.

The toString() method converts a Number object into a string and returns the result.

Syntax

NumberObject.toString(radix)
Copy after login

Parameters:

radix: Optional. Specifies the base in which the number is represented, making it an integer between 2 and 36. If this parameter is omitted, base 10 is used. Note, however, that the ECMAScript standard allows implementations to return any value if the parameter is a value other than 10.

Return value:

The string representation of the number. For example, when radix is ​​2, the NumberObject is converted to a string representing the binary value.

Note: A TypeError exception is thrown when the object calling this method is not Number.

Example:

var number = new Number(1337);
var str = number.toString()
console.log(str);
console.log(typeof str);
Copy after login

What is the function in js that converts a number into the corresponding string?

For more computer programming related knowledge, please visit: Programming Video! !

The above is the detailed content of What is the function in js that converts a number into the corresponding string?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template