Created
November 17, 2024 16:56
-
-
Save TGITS/e19f6d763b7f90331f2d0a52d29a24bc to your computer and use it in GitHub Desktop.
Comparing boolean or operator and null coalescing operator
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 i_am_false = false; | |
const zero = 0; | |
const empty_string = ''; | |
console.log(`Comparing the evaluation of (i_am_null ?? 'default value') and (i_am_null || 'default value'): | |
${i_am_null ?? 'default value'} <-> ${i_am_null || 'default value'}`); | |
console.log(`Comparing the evaluation of (i_am_undefined ?? 'default value') and (i_am_undefined || 'default value'): | |
${i_am_undefined ?? 'default value'} <-> ${i_am_undefined || 'default value'}`); | |
console.log(`Comparing the evaluation of (i_am_non_null ?? 'another value') and (i_am_non_null || 'another value'): | |
${i_am_non_null ?? 'another value'} <-> ${i_am_non_null || 'another value'}`); | |
console.log(`Comparing the evaluation of (i_am_false ?? 'default value') and (i_am_false || 'default value'): | |
${i_am_false ?? 'default value'} <-> ${i_am_false || 'default value'}`); | |
console.log(`Comparing the evaluation of (zero ?? 42) and (zero || 42): | |
${zero ?? 42} <-> ${zero || 42}`); | |
console.log(`Comparing the evaluation of (empty_string ?? "Non-empty") and (empty_string || "Non-empty"): | |
${empty_string ?? "Non-empty"} <-> ${empty_string || "Non-empty"}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment