Skip to content

Instantly share code, notes, and snippets.

@CristalT
Created April 8, 2019 14:14
Show Gist options
  • Save CristalT/cfe15807f3bf9f5a9aba33bccdae068a to your computer and use it in GitHub Desktop.
Save CristalT/cfe15807f3bf9f5a9aba33bccdae068a to your computer and use it in GitHub Desktop.
// 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