Skip to content
This repository was archived by the owner on Jan 28, 2023. It is now read-only.

this proposal is too confusing for users to use correctly. nodejs' util.isNullOrUndefined does the job already. #16

Closed
kaizhu256 opened this issue Nov 19, 2017 · 1 comment

Comments

@kaizhu256
Copy link

the more i work with code that has to differentiate between falsey and nullishness, the more i remain convinced its more maintainable to test for nullishness with with an explicit function-call. mixing and matching || and ?? will inevitably lead to spaghetti-code (plus how do you use it in the && case?).

real-world use-case with isNullOrUndefined here:
https://github.com/kaizhu256/node-swgg/blob/2017.10.17/lib.swgg.js#L3647

/*
 * how would ?? help in this use-case?
 */
            if (paramDef.valueEncoded === undefined &&
                    local.isNullOrUndefined(paramDef['x-example'])) {
                paramDef.valueEncoded = local.dbFieldRandomCreate({
                    modeNotRandom: true,
                    propDef: paramDef
                });
            }
@ljharb
Copy link
Member

ljharb commented Nov 19, 2017

It wouldn't; (without conditional assignment, which isn't part of this proposal) - this use case isn't covered by this proposal nor is it intended to be.

This proposal is particularly useful when looking up values in a chain with maybe-nullish intermediate values; it's not useful for mutating a maybe-nullish value.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants