For related language topics, browse the JavaScript tutorial index.
toString() converts a value into a string representation. It is useful when you want text output from numbers, arrays, booleans, or objects that support string conversion.
The method is common in display logic and debugging. Plain objects use
the default representation [object Object]; the guide to
printing JavaScript objects compares
console.log(), JSON.stringify(), console.table(), and property
iteration when that string is not useful. If you need formatted object
output instead, JSON.stringify pretty print is
the closer companion article.
Tested on: Node.js v20.18.2. A short note after each runnable snippet describes what you should see in the console.
Convert a number to a string
Numbers become string values that you can display or concatenate.
console.log("to-string-number:", (123).toString());You should see one line logging to-string-number: 123.
Use this when a numeric value needs to become text.
Convert an array to a string
Arrays are joined with commas by default.
console.log("to-string-array:", [1, 2, 3].toString());You should see one line logging to-string-array: 1,2,3.
This is useful when you want a quick text form of a list.
Convert a boolean to a string
Boolean values become true or false text.
console.log("to-string-boolean:", true.toString());You should see one line logging to-string-boolean: true.
This is handy when the value needs to be shown or logged as text.
Summary
JavaScript toString() converts values into readable string form. Use it for numbers, arrays, and booleans when you need text output, and use JSON.stringify() when you need a more complete object representation. The method is small, but it is part of a lot of ordinary display and logging code.
