Last active
March 4, 2020 20:40
-
-
Save thawkin3/8318366aac732febe5e03b8cc460e1c5 to your computer and use it in GitHub Desktop.
Finding values that are not null or undefined with nullish coalescing
This file contains 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 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