W3docs

How to Convert a Number to a String in JavaScript

Read the tutorial and find several easy and fast approaches to converting a number to a string in JavaScript. Choose the best method for your workflow.

There are several built-in methods in JavaScript that convert from an number data type to a String. Let’s discuss each of them.

toString()

The toString() method takes an integer or floating point number and converts it into a String type. There are two ways of invoking this method. If the base number is passed as a parameter to <kbd class="highlighted">toString()</kbd>, the number will be parsed and converted to it:

Javascript toString method

javascript— editable

String()

The <kbd class="highlighted">String()</kbd> method creates a primitive String type for the number passed to it:

Javascript String method

javascript— editable

The difference between the <kbd class="highlighted">String()</kbd> method and the String method is that the latter does not do any base conversions.

How to Convert a Number to a String in JavaScript

The template strings can put a number inside a String which is a valid way of parsing an Integer or Float data type:

Javascript template strings

javascript— editable

Template literals are string literals that allow embedded expressions. Multi-line strings and string interpolation features can be used with template literals.

Concatenating an Empty String

This method is considered one of the fastest way of converting a number into string.

Javascript converting a number into string

javascript— editable

However, be careful as this method sometimes may not return the preferable string:

Javascript concatenating an empty string

javascript— editable

The speed of these above methods differs by browsers.