X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook