Converting to a String with toString() method
The toString() method is available on values that are numbers, Booleans, objects, and strings. If a value is null or undefined, this method is not available.
<!DOCTYPE html>
<html>
<head>
<title>String Example</title>
<script type="text/javascript">
var age = 11;
var aString = age.toString(); //the string "11"
var found = true;
var anotherString = found.toString(); //the string "true"
document.writeln(anotherString);
</script>
</head>
<body>
</body>
</html>
Home
JavaScript Book
Language Basics
JavaScript Book
Language Basics
Data Types:
- JavaScript Data Types
- typeof Operator
- The Undefined Type
- null Type
- null vs undefined
- Boolean Type
- Boolean() casting function
- The Literials of Number Type
- Octal Integer
- Hexadecimal
- Floating-Point Values
- Value range
- NaN
- Number Conversions:Number(), parseInt() and parseFloat()
- Number() function
- parseInt()
- parseFloat()
- The String Type
- String Literals and Escapes
- Get the String Length
- Converting to a String with toString() method
- Convert Number to String with radix
- Convert to String with String() casting function