JavaScript (5) Truthy and Falsy

1. Falsy:

We say that value is Falsy if that value is coerced to a boolean and return false.

  • "" (empty string)
  • 0 and -0
  • NaN (not a number)
  • null
  • undefined
  • false

2. Truthy:

The value is Truthy if it is not Falsy.#$%^&**^&$%&^#^

  • "hello"
  • 42
  • true
  • [ ]
  • { }

Reference

[1] Kyle Simpson, You Don't Know JS Series, O'Reilly Media (2014)

留言

熱門文章