techhub.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A hub primarily for passionate technologists, but everyone is welcome

Administered by:

Server stats:

4.8K
active users

1/ W.r.t. optional parameters, JavaScript having both `undefined` and `null` becomes useful because we can distinguish between a parameter being `null` and it being omitted. (Probably not enough of an upside to outweigh the downsides elsewhere.)

In light of this, I’m wondering if we should try to never explicitly use `undefined`—unless we need to skip a positional parameter:

func(1, undefined, 3)

Often better: named parameters (see link below).

exploringjs.com/impatient-js/c

exploringjs.comCallable values • JavaScript for impatient programmers (ES2022 edition)

2/ Note that we can create our own special “parameter is missing” values via default parameter values (=we don’t really need a built-in `undefined`):

const MISSING = Symbol('MISSING');
function f(param = MISSING) {
return param === MISSING ? 'MISSING' : param;
}

Using this function:

> f()
'MISSING'
> f(undefined) // also triggers the default value
'MISSING'
> f(null)
null
> f('abc')
'abc'

@functionalscript I meant: If we have parameter default values, we don’t need a special “parameter is missing” value.