Test_expression ? statement1: statement2
If the given test expression is true, it returns statement1. If the test expression is false, statement2 is returned.
In this example, we will use the Ternary Operator to determine whether the person is eligible to vote.
When the user enters below 18, the condition will fail. So, the conditional will execute the second statement (which is after the : symbol will display).
When you open the browser, the below shown prompt box will open. We left to default 21 and Clicked OK. Here, the condition is true, so it prints the below output.
Let us look at the output
Vote Eligibility You are not eligible to Vote