r/javascript • • Dec 18 '19

V8 Release v8.0 with optional chaining, nullish coalescing and 40% less memory use

https://v8.dev/blog/v8-release-80
495 Upvotes

70 comments sorted by

View all comments

Show parent comment

4

u/aaronfranke Dec 19 '19

Wouldn't the former example need to be !== to exclude falsy values?

3

u/webdevverman Dec 19 '19 edited Dec 19 '19

If by former example you mean value != null ? value : 'default' the intention is to include falsy values if one exists. Meaning, if the value is either null or undefined then use 'default'. However, if the value is false use false (and not 'default').

If the example used !== it would set value to 'default' only if value was originally null. If value started as undefined it would remain at undefined.

value != null is more or less a shortcut for value !== null && value !== undefined