Last active
January 4, 2021 21:32
-
-
Save codingedgar/c0e21b331c945a140b447450c14128ec to your computer and use it in GitHub Desktop.
This file contains hidden or 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
console.group('Lazy Setter with Nullish Coalescing Operator'); | |
const nameThisCatPlease = new Cat('Pepo'); | |
console.assert(nameThisCatPlease.name === 'Pepo'); | |
nameThisCatPlease.name ?? ( nameThisCatPlease.name = 'Cleo') | |
console.assert(nameThisCatPlease.name === 'Pepo'); | |
nameThisCatPlease.name = undefined; | |
nameThisCatPlease.name ?? ( nameThisCatPlease.name = 'Cleo') | |
console.assert(nameThisCatPlease.name === 'Cleo'); | |
console.groupEnd(); | |
/* | |
Console: | |
Lazy Setter with Nullish Coalescing Operator | |
get called Pepo | |
get called Pepo | |
get called Pepo | |
set called undefined | |
get called undefined | |
set called Cleo | |
get called Cleo | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment