Logical or Boolean Operators part 2

Logical Operators



In the following example, we have connected two Boolean expressions with the AND operator.
(4 > 2) && (10 < 15)Try It Yourself

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";Try It Yourself

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".
Logical operators allow you to connect as many expressions as you wish.
Logical NOT returns true, if:

The operand is true
The operand is false

Comments

Popular posts from this blog

Introducing object part 3

Comparison Operators part 2

Module 2