Created
November 17, 2024 16:25
-
-
Save TGITS/fc4364571fbabb7966dd89de06c7e6b3 to your computer and use it in GitHub Desktop.
Basic example of how the nullish coalescing operator works
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
const i_am_null = null; | |
const i_am_undefined = undefined; | |
const i_am_non_null = 'I have value !' | |
const value_1 = i_am_null ?? 'default value'; | |
console.log(value_1); // Expected output: "default value" | |
const value_2 = i_am_undefined ?? 'another default value'; | |
console.log(value_2); // Expected output: "another default value" | |
const value_3 = i_am_non_null ?? 'another value'; | |
console.log(value_3); // Expected output: "I have value !" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment