THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript Type Conversion


JavaScript Type Conversion Table

The table below shows the result of converting different JavaScript values to Number, String, and Boolean:

Original
Value
Converted
to Number
Converted
to String
Converted
to Boolean
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: Values in quotes ("") indicate string values. Values in red indicate values (some) programmers might not expect.

For a tutorial about JavaScript Type Conversion, read our JavaScript Type Conversion Tutorial.