Mega Code Archive

 
Categories / JavaScript Tutorial / Number Data Type
 

Converting to a String

Booleans, numbers, and strings all have a toString() method to convert their value to a string. The Boolean toString() method simply outputs the string "true" or "false". var bFound = false; alert(bFound.toString());    //outputs "false" The Number toString() method has two modes: default and radix mode. In default mode, the toString() method outputs the numeric value in an appropriate string. var iNum1 = 10; var fNum2 = 10.0; alert(iNum1.toString());     //outputs "10" alert(fNum2.toString());     //outputs "10" In default mode, the Number's toString() returns the decimal representation of the number.