Larry S.
Larry S.

Reputation: 13

How to simplify this boolean / tenary expression?

How would I simplify this ternary expression?

c = a === false && b === false ? true : false;

c is true only when a and b are false.

Upvotes: 1

Views: 138

Answers (1)

Maheer Ali
Maheer Ali

Reputation: 36574

You don't need ternary expression here. The first expression itself returns are Boolean

c = a === false && b === false

Another trick you can use is compare a !== false with b

c = a !== false === b

Here there are only two values to check. If there are more values then its better use every method.

c = [a,b].every(x => x === false)

Upvotes: 2

Related Questions