JavaScript String(): Convert Numbers to Strings

Use String(value) to convert a number to text. String(1200) returns '1200' and leaves the original number unchanged. Use number formatting when you need digit grouping or a fixed number of decimals.

What String() returns

Use typeof to verify that the result is 'string'. Calling String() without an argument returns an empty string. Passing null or undefined produces their names as text. For ordinary conversion, leave out new. new String(0) is an object wrapping '0', so it is not strictly equal to '0'.

Call Result Type
String(1200) "1200" string
String(0) "0" string
String(false) "false" string
String(null) "null" string
String(undefined) "undefined" string
String() "" string
new String(0) "0" object

MDN’s String() reference

Addition, concatenation and formatting

Adding 12 and 3 gives 15. Convert each value first and + links them into '123'. Add first and convert afterward to get '15'. Before using a string in arithmetic again, check that it has the numeric format you expect.

See Number() conversion and input validation for a runnable example of the reverse conversion.

const a = 12;
const b = 3;
console.log(a + b);                  // 15
console.log(String(a) + String(b));  // "123"
console.log(String(a + b));          // "15"
console.log(String(1000.00));        // "1000"
console.log(String(Number('0012'))); // "12"
console.log(String(1e21));           // "1e+21"
console.log((1.2).toFixed(2));       // "1.20"
const format = new Intl.NumberFormat('de-DE');
console.log(format.format(1234.5));  // "1.234,5"

String(1000.00) produces '1000', and String(Number('0012')) produces '12'. Conversion cannot restore zeros lost when text became a number. Keep identifiers as strings from the start. Use toFixed(2) to show two decimal digits or Intl.NumberFormat for locale-specific separators.

ECMAScript specification for number conversion and display

See number formatting and thousands separators for examples of locale-specific output.

Choose a value and convert it in your browser

Save the example as string-conversion.html in UTF-8 and open it in a browser. The dropdown stores keys, and the Map provides the actual value. The first result shows number, '1200' and string. Try null and Symbol('id') too. JSON.stringify() adds visible quotes to the converted string, and textContent displays the result as plain text.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport"
        content="width=device-width, initial-scale=1">
  <title>Convert values to strings</title>
</head>
<body>
  <label for="sample">Value to convert</label>
  <select id="sample">
    <option value="number">1200</option>
    <option value="zero">0</option>
    <option value="boolean">false</option>
    <option value="null">null</option>
    <option value="undefined">undefined</option>
    <option value="bigint">42n</option>
    <option value="symbol">Symbol('id')</option>
  </select>
  <button id="convert" type="button">Convert</button>
  <pre id="output" aria-live="polite"></pre>
  <script>
    const values = new Map([
      ['number', 1200], ['zero', 0], ['boolean', false],
      ['null', null], ['undefined', undefined],
      ['bigint', 42n], ['symbol', Symbol('id')],
    ]);
    const sample = document.querySelector('#sample');
    const output = document.querySelector('#output');

    function convert() {
      const value = values.get(sample.value);
      const text = String(value);
      output.textContent = [
        "Original type: " + typeof value,
        "String representation: " + JSON.stringify(text),
        "Converted type: " + typeof text,
      ].join('\n');
    }

    document.querySelector('#convert').addEventListener('click', convert);
    convert();
  </script>
</body>
</html>

Missing values and symbols

To show missing values as an empty string, use String(value ?? ''). The ?? operator replaces only null or undefined, so it preserves zero and false. Calling String(Symbol('id')) explicitly returns 'Symbol(id)'. Interpolating a symbol directly in a template literal throws a TypeError. To send an object’s structure, choose a structured format such as JSON with the required serialization behavior.

const display = value => String(value ?? '');
console.log(JSON.stringify(display(null))); // '""'
console.log(display(0));                     // "0"
console.log(display(false));                 // "false"
console.log(String(Symbol('id')));           // "Symbol(id)"