Skip to content

Support nullish coalescing operator ?? in mathjs expression language #3353

Open
@gwhitney

Description

@gwhitney

Describe the suggested feature
Currently x ?? 0 is a syntax error. It would be handy if this meant the nullish coalescing operator denoted by ?? in JavaScript. For example, one could then do object lookup with a fallback : {foo: 7, bar: 3}["baz"] ?? 0.

Current workaround
nullish(x, y) = (x == null or x == undefined) ? y : x; nullish(null, 0)

I am not aware of a short way to test for null or undefined unlike x == null in JavaScript which is true if x is either null or undefined; in mathjs expression language it is true when x is null and false when x is undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:expressionsIssues about the expression parser, variable scoping etc.featureonlydust-waveContribute to awesome OSS repos during OnlyDust's open source week

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions