Primitive to primitive conversion table

suggest change
Value Converted To String Converted To Number Converted To Boolean
undefined “undefined” NaN No
null “null” 0 No
true “true” 1 Yes
false “false” 0 No
NaN “NaN” No
“” empty string 0 No
” “ 0 Yes
“2.4” (numeric) 2.4 Yes
“test” (non numeric) NaN Yes
“0” 0 Yes
“1” 1 Yes
-0 “0” No
0 “0” No
1 “1” Yes
Infinity “Infinity” Yes
-Infinity “-Infinity” Yes
[] “” 0 Yes
[3] “3” 3 Yes
[‘a’] “a” NaN Yes
[‘a’,’b’] “a,b” NaN Yes
{ } “[object Object]” NaN Yes
function(){} “function(){}” NaN Yes

A blank cell means the value is already of that type. Boolean(true) is true. A non-empty string, including "0" and " ", is true; Number(" ") is 0. The last five rows are objects, not primitives: objects are truthy, including an empty array.

Convert explicitly with String(), Number(), and Boolean().

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents