DEV Community

Discussion on: JavaScript Quiz

 
joshcheek profile image
Josh Cheek

You have to wrap it in parens b/c JS treats toplevel curlies as a "block" rather than an object. But, of course, if you begin a line with parens, then it will become a function call on the previous line, if one exists, so for sanity's sake, begin any paren line with a semicolon (same for brackets).

Personally, I think it's really iffy to say that {} and [] are falsy values. I've always understood "falsy" to mean you can drop it into a conditional and it will behave like false would have:

$ node -p ';[false, null, undefined, 0, NaN, "", [], {}].map(v => [v?"X":"√︎",v])'
[ [ '√︎', false ],
  [ '√︎', null ],
  [ '√︎', undefined ],
  [ '√︎', 0 ],
  [ '√︎', NaN ],
  [ '√︎', '' ],
  [ 'X', [] ],
  [ 'X', {} ] ]