Not null/undefined and has length when stringified vs Is truthy or 0 or false

Edit on GitHub

Setup

var tests = [
  '',
  null,
  false,
  0,
  'hi'
]

Tests

  • Not null/undefined and has length when stringified

    tests.forEach(function (V) {
      return (V != null && (""+V).length > 0)
    })
  • Is truthy or 0 or false

    tests.forEach(function (V) {
      return (!!V || V === 0 || V === false)
    })