Skip to content

Instantly share code, notes, and snippets.

@zeptobook
Created June 23, 2020 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeptobook/0cbd63126c91141bfd191d563b254192 to your computer and use it in GitHub Desktop.
Save zeptobook/0cbd63126c91141bfd191d563b254192 to your computer and use it in GitHub Desktop.
const nullValue = null;
const emptyText = ""; // falsy
const someNumber = 42;
const valA = nullValue ?? "default for A";
const valB = emptyText ?? "default for B";
const valC = someNumber ?? 0;
console.log(valA); // "default for A"
console.log(valB); // "" (as the empty string is not null or undefined)
console.log(valC); // 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment