Skip to main content

Logical Expressions

You use logical expressions to combine or manipulate Boolean values, particularly comparison expressions. For example, if your code needs to test whether two different comparison expressions are both true before proceeding, you can do that with a logical expression.

Operator Name Example (where x = 6 and y = 3) Result
&& AND (x < 10 && y > 1) true
|| OR (X == 5 || y == 5) false
! NOT ! (x == y) true

Example: Using the AND operator

<script language="JavaScript" type="text/javascript">
var left_operand = prompt("Enter the left Boolean value (true or false):", true)
var right_operand = prompt("Enter the right Boolean value (true or false):", 
var logical_result = left_operand &#38;&#38; right_operand

Next: One-Dimensional Arrays