Skip to content

Instantly share code, notes, and snippets.

@thawkin3
Last active March 4, 2020 20:40
Show Gist options
  • Save thawkin3/8318366aac732febe5e03b8cc460e1c5 to your computer and use it in GitHub Desktop.
Save thawkin3/8318366aac732febe5e03b8cc460e1c5 to your computer and use it in GitHub Desktop.
Finding values that are not null or undefined with nullish coalescing
const useCoolFeature1 = true
const useCoolFeature2 = false
const useCoolFeature3 = undefined
const useCoolFeature4 = null
const getUserFeaturePreference = (featurePreference) => {
return featurePreference ?? true
}
getUserFeaturePreference(useCoolFeature1) // true
getUserFeaturePreference(useCoolFeature2) // false
getUserFeaturePreference(useCoolFeature3) // true
getUserFeaturePreference(useCoolFeature4) // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment