THE WORLD'S LARGEST WEB DEVELOPER SITE

JavaScript String() Function

Function Reference 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);

The result of res will be:


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

Function Reference JavaScript Global Functions

COLOR PICKER

colorpicker

SHARE THIS PAGE






Search w3schools.com:

Translate w3schools.com: