JavaScript String toString()
- Forrige side
- Næste side
- Gå tilbage til toppen JavaScript String Reference Håndbog
Definition and usage
toString()
This method returns the string as a string.
toString()
This method does not change the original string.
toString()
This method can be used to convert a string object to a string.
See also:
Hint
Every JavaScript object has toString()
Method.
If you need to display an object as text (such as in HTML) or use an object as a string, JavaScript uses internally toString()
Method.
Generally, you will not use it in your own code.
Instance
Example 1
Get the text content:
let text = "Hello World!"; let result = text.toString();
Is equivalent to:
let text = "Hello World!"; let result = text;
Example 2
Get the value of the String object:
let text = new String("Hello World!"); let result = text.toString();
Syntax
string.toString()
Parameter
No parameters.
Return value
Type | Description |
---|---|
String | The content of the string. |
Throw
Exception | Description |
---|---|
TypeError | An exception is thrown if the object called with this method is not a String. |
Browser supports
toString()
Er ECMAScript1 (ES1) egenskaber.
Alle browsere understøtter fuldt ES1 (JavaScript 1997):
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
- Forrige side
- Næste side
- Gå tilbage til toppen JavaScript String Reference Håndbog