Skip to content

Instantly share code, notes, and snippets.

@indreklasn
Last active August 5, 2019 11:11
Show Gist options
  • Save indreklasn/ab52f675a81b35f87cd765b4922aa6dc to your computer and use it in GitHub Desktop.
Save indreklasn/ab52f675a81b35f87cd765b4922aa6dc to your computer and use it in GitHub Desktop.
const response = {
settings: {
nullValue: null,
height: 400,
animationDuration: 0,
headerText: '',
showSplashScreen: false
}
};
// result: 'some other default'
const undefinedValue = response.settings.undefinedValue ?? 'some other default';
// result: 'some other default'
const nullValue = response.settings.nullValue ?? 'some other default';
// result: ''
const headerText = response.settings.headerText ?? 'Hello, world!';
// result: 0
const animationDuration = response.settings.animationDuration ?? 300;
// result: false
const showSplashScreen = response.settings.showSplashScreen ?? true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment