React ES6 Ternary Operator


Ternary Operator

A ternary operator is a conditional operator that is simplified such as if / more.

Syntax: condition? <expression if true>: <expression if false>

Here is an example that uses if / else:


Before:
if (authenticated) {
            renderApp();
          } else {
            renderLogin();
          }
          

Here is a similar example using a ternary operator:


With Ternary
authenticated ? renderApp() : renderLogin();