Ternary operator : Operator « Language Basics « JavaScript DHTML






Ternary operator

  

<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
var w = 1, x = 2, y = 3, z = 4, ans; 
ans = (w > x) ? y : z
alert(ans);
</script>
</head>
<body>

</body>
</html>

   
    
  








Related examples in the same category

1.Using the Equal Operator
2.Examples of Increment and Decrement Operators
3.Operators and Expressions:Operator Summary Table
4.Working with the Increment Operator
5.Add two integer variables together
6.Subtract one integer variable from another integer variable
7.Multiply two integer variables together
8.Modular operation (remainder in division)
9.Prefix plus
10.Prefix subtraction
11.Postfix adding
12.Postfix subtraction
13.Postfix operator for integer
14.Prefix operator for integer
15.JavaScript compound plus assignment
16.JavaScript compound subtraction assignment
17.JavaScript compound multiply assignment
18.JavaScript compound divide assignment
19.Tenary operator