Ternary Operator
This lesson discusses ternary operator using an example.
We'll cover the following
The ternary operator is a comparison operator and it executes different statements based on a condition being true or false.
The ternary operator is shorthand syntax for
if-else
.
It allows to quickly test a condition and often
replaces a multi-line if
statement, making your code more compact.
Syntax
Here’s the syntax:
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy