10) Ternary Operator

The ternary operator is a shorthand structure which assigns different values to a variable depending on condition is true or false.

Ternary operator consists of (?:)

This is equivalent to normal if else condition:

Example

Use ternary operator to tell value is true or false. It is easy to write and saves you from writing a lot of code then an conditional if else statement.