Convert to String with String() casting function
String() casting function is useful for null or undefined value. The String() function follows these rules:
Value | Returns |
---|---|
value with toString() method | called toString without arguments |
null | "null" string |
undefined | "undefined" string |
<!DOCTYPE html>
<html>
<head>
<title>String Example</title>
<script type="text/javascript">
var value1 = 1;
var value2 = true;
var value3 = null;
var value4;
document.writeln(String(value1)); //"1"
document.writeln(String(value2)); //"true"
document.writeln(String(value3)); //"null"
document.writeln(String(value4)); //"undefined"
</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