Primitive to primitive conversion table

suggest change

Value Converted To String Converted To Number Converted To Boolean
undefinded “undefined” NaN No
null “null” 0 No
true “true” 1 No
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

Bold values highlight conversion that programmers may find surprising

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

Feedback about page:

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


Variable coercion / conversion:
* Primitive to primitive conversion table

Table Of Contents
11 Arrays
12 Objects
14 Classes
15 Variable coercion / conversion
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde