← BYTES
JavaScript·Starter·Ref: 3.1.18

What is the purpose of the ternary operator `condition ? a : b`?

Have a question about this video? Mention reference 3.1.18 when you contact us.

a.A compact conditional expression that evaluates to `a` if the condition is truthy, or `b` otherwise
b.Declares three variables at once
c.Checks if a value is between two bounds
d.Only usable inside loops
The ternary operator is a single-expression shorthand for a simple if/else that produces a value, commonly used for concise inline conditional assignment, e.g. `const label = isActive ? "On" : "Off";`.

Find this on YouTube & Instagram

Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:

#BYTES#BYTES3118#JavaScript