JavaScript Type Conversion
- Previous Page CSSStyleDeclaration
- Next Page JS Reference Manual (Sorted by Category)
JavaScript Type Conversion Table
The following table shows the results of converting different JavaScript values to Number, String, and Boolean:
Original value | Convert to number | Convert to string | Convert to boolean value | Try It |
---|---|---|---|---|
false | 0 | "false" | false | Try It |
true | 1 | "true" | true | Try It |
0 | 0 | "0" | false | Try It |
1 | 1 | "1" | true | Try It |
"0" | 0 | "0" | true | Try It |
"1" | 1 | "1" | true | Try It |
NaN | NaN | "NaN" | false | Try It |
Infinity | Infinity | "Infinity" | true | Try It |
-Infinity | -Infinity | "-Infinity" | true | Try It |
"" | 0 | "" | false | Try It |
"20" | 20 | "20" | true | Try It |
"twenty" | NaN | "twenty" | true | Try It |
[ ] | 0 | "" | true | Try It |
[20] | 20 | "20" | true | Try It |
[10,20] | NaN | "10,20" | true | Try It |
["twenty"] | NaN | "twenty" | true | Try It |
["ten","twenty"] | NaN | "ten,twenty" | true | Try It |
function(){} | NaN | "function(){}" | true | Try It |
{ } | NaN | "[object Object]" | true | Try It |
null | 0 | "null" | false | Try It |
undefined | NaN | "undefined" | false | Try It |
Note:The value in quotes ("") represents a string value. The red value represents a value that the programmer may not want.
For more knowledge about JavaScript type conversion, please read our JavaScript Type Conversion Tutorial.
- Previous Page CSSStyleDeclaration
- Next Page JS Reference Manual (Sorted by Category)