Convert different values to strings:
String(new Date());
String("12345");
String(12345);
Try it Yourself »
The String()
method converts a value to a string.
The String() method returns the same as the toString() method for any value.
String(
value)
Parameter | Description |
value | Required. A JavaScript value. |
Type | Description |
A string. | The value converted to a string. |
String()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
Convert different values to strings:
String(Boolean(0));
String(Boolean(1));
String([1,2,3,4]);
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!