HOLLA TECH - LEARN

Logical Operators
 

Logical Operators, also known as Boolean Operators, evaluate the expression and return true or false.

The table below explains the logical operators (AND, OR, NOT). 

Holla Tech - Learn JavaScript

NOTE!
You can check all types of data; comparison operators always return true or false.

Logical Operators
 

In the following example, we have connected two Boolean expressions with the AND operator. 

(4 > 2) && (10 < 15)

 

For this expression to be true, both conditions must be true.
– The first condition determines whether 4 is greater than 2, which is true.
– The second condition determines whether 10 is less than 15, which is also true.
Based on these results, the whole expression is found to be true.

Conditional (Ternary) Operator
Another JavaScript conditional operator assigns a value to a variable, based on some condition.
Syntax:

variable = (condition) ? value1: value2 

 

For example:

var isAdult = (age < 18) ? "Too young": "Old enough"

 

If the variable age is a value below 18, the value of the variable isAdult will be "Too young". Otherwise the value of isAdult will be "Old enough".  

NOTE!
Logical operators allow you to connect as many expressions as you wish.

BACK NEXT

CLICK ON THE BUTTON BELOW TO GO TO THE JAVASCRIPT MAIN COURSE PAGE. 

JAVASCRIPT MAIN COURSE PAGE

 


© License: All Rights Reserved 


CONTACT HOLLA TECH – LEARN SUPPORT