JavaScript String toString()
Example
Get the content of the text:
let result = text.toString();
Same as:
let result = text;
More examples below.
Description
The toString()
method returns a string as a string.
The toString()
method does not change the original string.
The toString()
method can be used to convert a string object into a string.
See Also:
Note
Every JavaScript object has a toString()
method.
The toString()
method is used internally by JavaScript
when an object needs to be displayed as a text (like in HTML),
or when an object needs to be used as a string.
Syntax
Parameters
Return Value
More Examples
Get the value of a String object:
let result = text.toString();
Browser Support
toString()
is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |