Created
April 8, 2019 14:14
-
-
Save CristalT/cfe15807f3bf9f5a9aba33bccdae068a 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
// hypothetical undefined value | |
const name = undefined | |
// Way 1: | |
const firstName1 = name || 'Marcelo' | |
console.log(firstName1) | |
// Way 2: | |
const firstName2 = name ? name : 'Marcelo' | |
console.log(firstName2) | |
// Way 2 is equal to do: | |
let firstName3 | |
if (name) { | |
firstName3 = name | |
} else { | |
firstName3 = 'Marcelo' | |
} | |
console.log(firstName3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment