Last active
November 29, 2021 12:14
-
-
Save juniorgarcia/7e114d6125598b8202f442d3f6ea9055 to your computer and use it in GitHub Desktop.
Truthy and falsy cheat sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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