Ternary Operator:

The “Question mark” or “conditional” operator in JavaScript is a ternary operator that has three operands. It is the simplified operator of if/else.



Examples:

Input: let result = (10 > 0) ? true : false; Output: true

Input: let message = (20 > 15) ? "Yes" : "No"; Output: Yes

Syntax:

condition ? value if true : value if false

<!DOCTYPE html>
<html>
<head>
  <title>JavaScript</title>
  <script>
    var a = 100;
    var b;
    b = "Value is " + (a > 10 ? "True" : "False");

    document.write(b);
  </script>
</head>
<body>
</body>
</html>