This example shows you how to use the abbreviated if/then expression.
Source for shortifthen.html
var x, test;
x = 2;
test = (x > 1) ? 1:0

This example declares the two variables x, and test. Then sets x to be 2. The expression test = (x > 1) ? 1:0 checks to see if x is greater than 1. If it is greater, then the expression will set test to be 1, if x is not greater than 1, it will set test to be 0.

In this case, since we have set x to be 2, it is greater than 1, so test is set to 1.

Back