Skip to content

Instantly share code, notes, and snippets.

@TGITS
Created November 17, 2024 16:25
Show Gist options
  • Save TGITS/fc4364571fbabb7966dd89de06c7e6b3 to your computer and use it in GitHub Desktop.
Save TGITS/fc4364571fbabb7966dd89de06c7e6b3 to your computer and use it in GitHub Desktop.
Basic example of how the nullish coalescing operator works
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