Conditions need a boolean, so JS coerces. The falsy values are exactly: false, 0, "", null, undefined, NaN (and 0n). Everything else is truthy — including "0", [], and {}. Boolean(x) or !!x converts explicitly.
Conditions need a boolean, so JS coerces. The falsy values are exactly: false, 0, "", null, undefined, NaN (and 0n). Everything else is truthy — including "0", [], and {}. Boolean(x) or !!x converts explicitly.
<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const v=[0,'','0',[],{}].map(x=>JSON.stringify(x)+' → '+!!x);
document.getElementById('o').textContent=v.join('\n');</script></body></html>▶ Open the interactive comic issue