Javascript - Global String() Function

The String() function converts a value to a string.

Description

The String() function converts a value to a string.

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

Syntax

String(object)

Parameter Values

Parameter RequireDescription
objectRequired. A JavaScript object

Example

Convert different objects to strings:

Demo

var x1 = Boolean(0);
var x2 = Boolean(1);
var x3 = new Date();
var x4 = "12345";
var x5 = 12345;//from   w  w  w  .  j  a  v a 2  s  .  c o m

var res =
    String(x1) + "\n" +
    String(x2) + "\n" +
    String(x3) + "\n" +
    String(x4) + "\n" +
    String(x5);
console.log(res);

Result