JavaScript uses something called a ''ternary operator'' to provide a shortcut way of making decision in a script. The syntax of the ternary operator is as follows:
+
JavaScript uses something called a ''ternary operator'' to provide a shortcut way of making decisions in a script. The syntax of the ternary operator is as follows:
The way this works is that ''[condition]'' is replaced with an expression that will return either ''true'' or ''false''. If the result is ''true'' then the expression that replaces the ''[true expression]'' is evaluated. Conversely, if the result was false then the ''[false expression]'' is evaluated. Let's see this in action:
The way this works is that ''[condition]'' is replaced with an expression that will return either ''true'' or ''false''. If the result is ''true'' then the expression that replaces the ''[true expression]'' is evaluated. Conversely, if the result was false then the ''[false expression]'' is evaluated. Let's see this in action: