Skip to content

Instantly share code, notes, and snippets.

@cold-logic
Last active March 5, 2020 21:32
Show Gist options
  • Save cold-logic/9b359ba64ca4e27a456437cad92af4ad to your computer and use it in GitHub Desktop.
Save cold-logic/9b359ba64ca4e27a456437cad92af4ad to your computer and use it in GitHub Desktop.
Check a value and return true for null or undefined
// Exclude zero (0) which is typically falsy
let isEmpty = (x) => x == 0 ? false : !(x)
/* Tests (run in Node CLI)
> isEmpty(0)
false
> isEmpty(1)
false
> isEmpty(1.5)
false
> isEmpty(true)
false
> isEmpty(false)
false
> isEmpty('hi')
false
> isEmpty(null)
true
> isEmpty(undefined)
true
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment