Last active
April 3, 2022 13:29
-
-
Save gilles-gardet/919f94ecad87fc85d59306c438e3a1b9 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
| let data = undefined ?? 'noData' | |
| console.log(data) // noData | |
| data = null ?? 'noData' | |
| console.log(data) // noData | |
| data = '' ?? 'noData' | |
| console.log(data) // '' | |
| data = 0 ?? null ?? 'noData' | |
| console.log(data) // 0 | |
| // when we assign value based on itself value it is "Shorthand" way | |
| data ??= 'noData' | |
| console.log(data) // 0 | |
| Confuse 😕 with OR(||) Operator ?? | |
| OR operator used when you want conditionally assign other value if the value is not truthy(0,’ ’, null, undefined, false, NaN) | |
| let data = undefined || 'noData' | |
| console.log(data) // noData | |
| data = null || 'noData' | |
| console.log(data) // noData | |
| data = '' || 'noData' | |
| console.log(data) // noData | |
| data = 0 || null || 'apple' | |
| console.log(data) // apple | |
| // when we assign value based on itself value it is "Shorthand" way | |
| data ||= 'noData' | |
| console.log(data) // apple |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment