Implicit conversion

suggest change

JavaScript will try to automatically convert variables to more appropriate types upon use. It’s usually advised to do conversions explicitly (see other examples), but it’s still worth knowing what conversions take place implicitly.

"1" + 5 === "15" // 5 got converted to string.
1 + "5" === "15" // 1 got converted to string.
1 - "5" === -4 // "5" got converted to a number.
alert({}) // alerts "[object Object]", {} got converted to string.
!0 === true // 0 got converted to boolean
if ("hello") {} // runs, "hello" got converted to boolean.
new Array(3) === ",,"; // Return true. The array is converted to string - Array.toString();

Some of the trickier parts:

!"0" === false // "0" got converted to true, then reversed.
!"false" === false // "false" converted to true, then reversed.

Feedback about page:

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


Variable coercion / conversion:
* Implicit conversion

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