Mega Code Archive

 
Categories / JavaScript Tutorial / Number Data Type
 

Casting type to string

When casting type to string, JavaScript simply calls the toString() method. The type cast can produce a string for a null or undefined value without error. var s1 = String(null);    //"null" var oNull = null; var s2 = oNull.toString(); //won't work, causes an error