Default argument deferring to the required one

Regardless the language, this filter must have come up somewhere, the idea of A OR B where B is optional and the logic is A OR B in either case.

How would we implement this in say, JavaScript?

Might the wiser of us choose to use two filters?

You’d start with a check that B is valid, e.g. not null, undefined, None, etc. If it isn’t then A otherwise do A OR B .

1 Like