Would there be any support for the idea of accepting nullish-colescing type of syntax for the default parameter values?
The syntax would use the provided default value for both null
and undefined
param values, just like nullish
In this example:
function setColor(color ?? '#aaa') { }
would be similar to:
function setColor(color = '#aaa') { }
except it would not only handle color
equal to undefined
but also null
, just like : const foo = null ?? 'default string'
Of course the syntax would apply to each parameter in case of multiple parameter functions.
Supporting this would result in much simpler code, where you need to guard your code against null
values. An example could be Angular where resetting form controls results in their value being null
rather than undefined
. Should you want to process the values for other purpose, you need to capture the null
s properly.
Also, the proposal seems like a very legit counterpart of the already supported object nullish coalescing in assignments - all in all, a default parameter is also an assignment.