The Ternary Operator

Published on: November 19, 2016

Welcome to the twenty-second Easy JavaScript tutorial, part of EasyProgramming.net. In this tutorial, we will take a quick look at writing conditional statements using the ternary operator. 

The ternary operator is the only JavaScript operator that takes three operands. This is usually used as the shortcut for if...else statements. 

The ternary operator syntax normally looks like this:

    (if condition true) ? do this : else do this;
    (if condition1 true) ? do this : (else condition2 true) ? do this : else do this; 

To fork the fiddle and follow along: https://jsfiddle.net/easyjs/atyusxvd/

Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!

Resources:



Comments: