Concise syntax for comparing multiple values

Problem

When multiple values need to satisfy the same condition, the condition has to be repeated:

if (a === 1 && b === 1 && c === 1) {}

This can become verbose when the same comparison is repeated for many values.

Proposed syntax

A possible syntax could be:

if ((a, b, c) === 1) {}

Similarly:

if (typeof (a, b, c) === "number") {}

The goal is to provide a concise way to apply the same comparison or type check to multiple expressions.

I'd like to get feedback on whether this is useful and whether there are better syntax or semantic alternatives.

no, it couldn't, because (a, b, c) is already valid syntax using the comma operator.

Either way, it sounds to me like the problem you're solving is at best a mild inconvenience, which is a low value for something with such a high cost as syntax.

you could always do [a, b, c].every(x => x === 1) if verbosity is a problem?

1 Like