THE WORLD'S LARGEST WEB DEVELOPER SITE

JavaScript String() Function

❮ JavaScript Global Functions

Example

Convert different objects to strings:

var x1 = Boolean(0);
var x2 = Boolean(1);
var x3 = new Date();
var x4 = "12345";
var x5 = 12345;

var res =
String(x1) + "<br>" +
String(x2) + "<br>" +
String(x3) + "<br>" +
String(x4) + "<br>" +
String(x5);
Try it Yourself »

Definition and Usage

The String() function converts the value of an object to a string.

Note: The String() function returns the same value as toString() of the individual objects.


Browser Support

Function
String() Yes Yes Yes Yes Yes

Syntax

String(object)

Parameter Values

Parameter Description
object Required. A JavaScript object

❮ JavaScript Global Functions