Computer Science, asked by papiyasarkar8006, 4 months ago

4. Write only the syntax of ternary(conditional) operator in javascript.​

Answers

Answered by deepakkumar9254
4

Solution :-

A ternary operator is the one which uses three operands to work.

Symbol - ( ? : )

Syntax :-

condition\:\:?\:\:statement\:\:1\:\: : \:\:statement \:\:2;

1. If the condition is true, statement 1 will be executed.

2. If the condition is false, statement 2 will be executed.

Example to explain it's functioning -

\longrightarrow First Example

10<20\:\:?\:\:"Yes"\:\: : \:\:"No";

Here,

Condition is - 10 < 20

First Statement is - "Yes"

Second Statement is - "No"

Output - in the attachment.

The condition is asking that 20 is greater than 10. Obviously, we all know that 20 is greater 10. So, the condition is true. Therefore, "Yes" will be printed.

\longrightarrow Second Example

10&gt;20\:\:?\:\:"Yes"\:\: : \:\:"No";

Condition is - 10 > 20

First Statement is - "Yes"

Second Statement is - "No"

Output - in the attachment.

Here, the condition is asking that 10 is greater than 20.

So, the condition becomes false as 20 is greater than 10. Therefore, second statement "No" will be printed.

Attachments:
Similar questions