Learn JavaScript
Conditionals
11.9
Lesson

if...else shorthand

We can use ? to execute a block of code when the given condition is true and execute another block of code when the condition is false.

In the example given below, when the condition at left of ? is true, we get even in the output. But when the condition is false, we get false in the output.

If you change the value of x to 5, the output changes to odd.