#24: Boolean(' ') vs Boolean('')
Topic: coercion · Difficulty: ★
console.log(Boolean(' '));
console.log(Boolean(''));Output
true false
Why
JavaScript's falsy-string rule is about LENGTH, not visible content: the only falsy string is the exact empty string '' (length 0). A single space ' ' has length 1, so even though it looks empty and contains no visible characters, it's truthy just like any other non-empty string. This trips people up when trimming user input is skipped — a field containing only spaces will pass a truthy check like `if (input)` even though it has nothing meaningful in it.
More coercion puzzles