Last Updated: February 25, 2016
·
585
· marbio

Shorter IF statement for Javascript

There is a good alternative way of writing an if statement where both conditions (true and false) are just assigning different values to the same variable.

variable = (condition) ? true value : false value;

For example:

var imageFormat = ( device === 'desktop' ) ? 'large' : 'small';