Javascript String function converts an object into string. String function returns the exact equivalent of the value passed as parameter. If number is passed to the javascript String function then it returns the number as string. Boolean 0 or 1 value is returned as their equivalent string matches i.e. true for 1 and false for 0. Full Date format is returned by the string function when Date object is passed as the parameter. Please note that when Boolean true/false or number is passed to the Javascript String function they remain unchanged only their back end data type is converted into string type that is directly related to memory overheads for storing the variables and their values according to the object type.

Javascript String Function Syntax

String(object);

Javascript String Function Examples

var string1= new String("123 456 789");
document.write(String(string1)+ "<br />");
 
var string2= new Date();
document.write(String(string2)+ "<br />");
   
var string3= 12345;
document.write(String(string3)+ "<br />");
   
var string4= new Boolean(true);
document.write(String(string4)+ "<br />");
   
var string5= new Boolean(false);
document.write(String(string5)+ "<br />");
   
var string6= new Boolean(1);
document.write(String(string6)+ "<br />");
   
var string7= new Boolean(0);
document.write(String(string7)+ "<br />");

Continue to next tutorial: Javascript toString Function to learn about the string conversions.

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.