-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTernary-Operator.htm
33 lines (24 loc) · 1011 Bytes
/
Ternary-Operator.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ternary-Operator</title>
</head>
<body>
<h1>Ternary Operator</h1>
<script>
var number = 9;
var message="Hello World ";
message = (number === 9) ? "Correct!" : "Incorrect!";
console.log(message);
// alert(message);
// variable_name = (condition) ? value_if_true : value_if false;
// Ternary Operator
// ternary operator which takes three operands rather than the typical one or two that most
// operators use. It provides a way to shorten a simple if else block.
// A ternary operator evaluates the test condition and executes a block of code based on the result of the condition. Its syntax is condition ? expression1 : expression2; Here, condition is evaluated and. if condition is true , expression1 is executed.
</script>
</body>
</html>