Javascript Ternary Operator

The Ternary Operator is an Operator in Javascript that works with 3 operands. It's a short way to express conditionals.

It looks like this

    <Condition> ? <expression> : <expression>

The condition is evaluated as Boolean, and upon the Result,If the Condition is True, The Operator runs the First Expression , otherwise it runs the second one .

Here is an Example :

const Boolean = true;

Boolean === true ? play() : stop();

We check in the above example if Boolean is True , and if it's the case we call the play() function otherwise we call the stop() function

Maher Gallaoui

You like our Content? Follow us to stay up-to-date.