The conditional operator in Javascript is the only ternary operator (three operands).
greeting = "hello" + ((username !=null) ? username : "there");
The first operand goes before the ?, the second goes between the ? and the :, and the third goes after the :.
The first operand of the conditional operator must have a boolean value — usually the result of a comparison expression. The second and third operands may have any value. If the first operand is true, then the value of the conditional expression is the value of the second operand. If it is false, then the value is the value of the third operand.
Tagged As Javascript
Comments are Open (0)
Posted at 12:00 PM