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

JavaScript String() Function

Function Reference JavaScript Global Functions

Example

Convert different objects to strings:

var test1 = new Boolean(1);
var test2 = new Boolean(0);
var test3 = new Boolean(true);
var test4 = new Boolean(false);
var test5 = new Date();
var test6 = new String("999 888");
var test7 = 12345;

var res = String(test1) + "<br>" + String(test2) + "<br>" + String(test3) + "<br>" + String(test4) + "<br>" + String(test5) + "<br>" + String(test6) + "<br>" + String(test7);

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

Internet Explorer Firefox Opera Google Chrome Safari

The String() function is supported in all major browsers.


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 BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE