The String() function converts a value to a string.
The String() function converts a value to a string.
The String() function returns the same value as toString() of the individual objects.
String(object)
Parameter | Require | Description |
---|---|---|
object | Required. | A JavaScript object |
Convert different objects to strings:
var x1 = Boolean(0); var x2 = Boolean(1); var x3 = new Date(); var x4 = "12345"; var x5 = 12345;/* ww w .j a va 2s . com*/ var res = String(x1) + "\n" + String(x2) + "\n" + String(x3) + "\n" + String(x4) + "\n" + String(x5); console.log(res);