Ternary Operators and Conditionals
Introduction to ternary operators and how they are used in JavaScript.
Background
Conditional statements execute code dependent on a condition. It is common for conditionals to alter program flow.
In the code snippet below, we assigned 0 or 1 depending on whether the original value is 0, 1, or -1. We wrote multiple lines of code for a single assignment, as shown below.
Get hands-on with 1400+ tech skills courses.