Last active
December 6, 2019 04:57
-
-
Save daubattu/1e728e12a97e27a1481027cfe64628e4 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
const number1 = 10; | |
const number2 = 0; | |
// Written as of ES2019 | |
const score1 = number1 || 1; | |
console.log(score1); // 10 | |
const score2 = number2 || 1; | |
console.log(score2); // 1 | |
// Using nullish coalescing | |
const score1 = number1 ?? 1; | |
console.log(score1); // 10 | |
const score2 = number2 ?? 1; | |
console.log(score2); // 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment