DEV Community

Discussion on: Safe Navigation Operator? Bang! Bang Bang!!

Collapse
 
kinakuta profile image
James Donaldson

The safe navigation operator also pairs well with the nullish coalescing operator for providing defaults like what you get with lodash get:

const foo = get(a, 'b', {});

can be expressed as

const foo = a?.b ?? {};

And the nullish coalescing operator protects from logical bugs where you want 0 or false to be considered valid values.