A ternary operator, as denoted by name, requires three operands.

Is grammar a condition? Result 1: Result 2; Here you write the condition in question mark (?) Result 1 and result 2 are preceded by a colon (:). Result 1 if this condition is satisfied otherwise result 2.

<script type="text/javascript"> var b=5; (b == 5) ? a="true" : a="false"; document.write(" --------------------------- "+a); < / script > result: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- true < script type = "text/javascript" > var b = true; (b == false) ? a="true" : a="false"; document.write(" --------------------------- "+a); </script> Result: --------------------------- falseCopy the code