Nullish Coalescing is at Stage 3. This one is interesting.
tc39 / proposal-nullish-coalescing
Nullish coalescing proposal x ?? y
Nullish Coalescing for JavaScript
Status
Current Stage:
- Stage 4
Authors
- Gabriel Isenberg (github, twitter)
- Daniel Ehrenberg (github, twitter)
- Daniel Rosenwasser (github, twitter)
Overview and motivation
When performing property accesses, it is often desired to provide a default value if the result of that property access is null
or undefined
. At present, a typical way to express this intent in JavaScript is by using the ||
operator.
const response = {
settings: {
nullValue: null,
height: 400,
animationDuration: 0,
headerText: '',
showSplashScreen: false
}
};
const undefinedValue = response.settings.undefinedValue || 'some other default'; // result: 'some other default'
const nullValue = response.settings.nullValue || 'some other default'; // result: 'some other default'
This works well for the common case of null
โฆ
Top comments (0)