Skip to content

Instantly share code, notes, and snippets.

@codingedgar
Last active January 4, 2021 21:30
Show Gist options
  • Save codingedgar/d370b1554e4b8fb487d1c3666501b6ac to your computer and use it in GitHub Desktop.
Save codingedgar/d370b1554e4b8fb487d1c3666501b6ac to your computer and use it in GitHub Desktop.
console.group('Exemplifying the difference between falsy and nullish');
const catWithNoChars = new Cat('');
console.assert(catWithNoChars.name === '');
// '' is falsy but no nullish
if (!catWithNoChars.name) {
catWithNoChars.name = 'Pepo';
}
console.assert(catWithNoChars.name === ''); // Assertion failed
console.groupEnd();
/*
Console:
Exemplifying the difference between falsy and nullish
get called
get called
set called Pepo
get called Pepo
Assertion failed
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment