🔰type conversion
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
JS ⟩ value ⟩ type ⟩ conversion
When JS expects a boolean, a value of any type can be supplied, and JS will convert it as needed. The same is true for all types.
// ⭐ explicit type conversion
Number(' 012'), // 12
String(34), // '34'
Boolean({}), // true
// ⭐ implicit type conversion
+' 012', // === Number(' 012')
34 + '', // === String(34)
!!{}, // === Boolean({})
replit: type conversion table (require: TableMaker)
┌── (primitive?)
│ (-> number) (-> string)
│ x desc +x String(x)
────────────────────────────────────────────────────────────────────
✅ null 0 "null"
────────────────────────────────────────────────────────────────────
✅ undefined
💍 falsy
!!x // any -> true/false, same as Boolean(x)
+x // any -> number, same as `Number(x)`