HTML and CSS Reference
In-Depth Information
EXAMPLE 5.10
<html>
<head>
<title>Logical NOT Operator</title>
</head>
<body bgcolor="lightblue">
<big>
<script type="text/javascript">
1
var answer = true ;
2
alert("Was true. Now it is " + ! answer );
</script>
</big>
</body>
</html>
EXPLANATION
1
The Boolean value true is assigned to the variable answer .
2
The expression sent to the alert dialog box, ! answer , negates the value true (not
true), making it false . (See Figure 5.15.)
Figure 5.15 The logical “not” operator changes true to false or false to true. The !
operator caused true to become false.
In summary, Example 5.11 illustrates the logical operators and the values they return.
EXAMPLE 5.11
<html>
<head>
<title>Logical (Boolean) Operators</title>
</head>
<body>
<h3>
<script type = "text/javascript">
1
var num1=50;
var num2=100;
var num3=0;
 
Search WWH ::




Custom Search