Skip to content

Instantly share code, notes, and snippets.

@juniorgarcia
Last active November 29, 2021 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juniorgarcia/7e114d6125598b8202f442d3f6ea9055 to your computer and use it in GitHub Desktop.
Save juniorgarcia/7e114d6125598b8202f442d3f6ea9055 to your computer and use it in GitHub Desktop.
Truthy and falsy cheat sheet
// Cheat sheet para verificar quais valores são truthy e falsy
const vals = {
0: 0,
1: 1,
'Número negativo': -1,
true: true,
false: false,
null: null,
undefined: undefined,
'Objeto vazio': {},
'Array vazio': [],
'Objeto preenchido': { foo: 'bar' },
'Array preenchido': [1, 2, 3],
Function: () => {},
}
const result = Object.entries(vals).reduce(
(acc, [label, val]) =>
acc.concat(`${label} é ${Boolean(val) ? 'truthy' : 'falsy'}\n`),
''
)
console.log(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment