JavaScript Primitive to Primitive conversion table


Example

ValueConverted To StringConverted To NumberConverted To Boolean
undefinded"undefined"NaNfalse
null"null"0false
true"true"1
false"false"0
NaN"NaN"false
"" empty string0false
" "0true
"2.4" (numeric)2.4true
"test" (non numericNaNtrue
"0"0true
"1"1true
-0"0"false
0"0"false
1"1"true
Infinity"Infinity"true
-Infinity"-Infinity"true
[]""0true
[3]"3"3true
['a']"a"NaNtrue
['a','b']"a,b"NaNtrue
{ }"[object Object]"NaNtrue
function(){}"function(){}"NaNtrue

Bold values highlight conversion that programmers may find surprising

To convert explicitly values you can use String() Number() Boolean()