Skip to content

Instantly share code, notes, and snippets.

TLDR;

Optional spreading [?...ArrayOrNullish] {?...ObjectOrNullish}. Noop when spreading value is nullish. Intuitive addition to javascript, inspired by optional chaining and Nullish coalescing operator

Problem

Spreading is great, it contributes towards "declerativity" of the language and reduces verbosity, but in case value being spread is nullish, we either have to give up on this feature or sacrifice verbosity and performance for declarativity.

Consider following code pattern that naturally appears in configuartion management

function getConfig(customConfig) {
 return {