# The Logical Operators

The logical operators are primarily used to control the program flow. The concept of logical operators is to allow programs to make decisions based on multiple terms and conditions. Each of the operands is considerably conditioning to determine the overall value. The logical operators have the symbol of two vertical lines **(l l).**

In classical programming, the logical operators meant to navigate the Boolean values only. If any of the arguments are ** true**, then it returns

**. If otherwise, it returns**

__true__**. In JavaScript, the operators are somewhat trickier and more powerful.**

__false__### The logical operators do the following:

- It evaluates the operands starting from the left part to the right.
- In each operand converts into Boolean. If the result is
, it stops and reverts to the original value.__true__ - All the operands resulted
will revert to the last operand.__in false__

Values will return to its normal form without the conversion. In other words, the chain of logical operators returns the first true value or the last one if no true value found.

**&& (AND)**

The AND operator has the symbol of two ampersands **(&&). **In classical programming, AND returns true If both operands are truthy and false.

The AND (&&) operator does the following:

- Evaluates the operands from the left part to the right
- In each operand, convert it to Boolean. If the result is
, it stops and returns the original value of the operand.__false__ - All the operands evaluated truthy will return the last operand.

In other words, AND will return the first falsy value or the last value if found none. The rules are just similar to OR. The difference is that, AND will return the falsy value while OR returns the first truthy value. When all the values are truthy, then the last value will return.

**! (NOT)**

This logical operator has the symbol of an exclamation sign **(!)**. The operator only accepts a single argument and only does the following:

- Converts the operand to Boolean type:
the inverse value__true/false returns__

Note that a double not **(!!)** means to convert an amount into Boolean type. The precedence of **NOT (!) **is the highest of all logical operators. It is always to execute first following by ** &&** or

**.**

__I I__Logical expressions can only have the values of true and false. There are relational operators used to structure rational expressions. Logical operators are used to comparing two values having the same type. the table below will show the relational operators along with their meanings.

### **Operator / ****Meaning**

.eq.

Equal to

.ne.

Not equal to

.lt.

Less than

.le.

Less than or equal to

.gt.

Greater than

.ge.

Greater than or equal to

Some logical operators only used between complete logical expressions. The table below will show the logical operators along with the meanings:

### **Operator / ****Meaning**

.not.

Changes the value of the expression into the opposite value

.and.

TRUE only if both the logical expressions are TRUE

.or.

TRUE if either the logical expression is TRUE

.xor.

TRUS if only one expression is true

.eqv.

TRUE if the expression has the same truth value

.neqv.

TRUE if the expression does not have the same value

**Conclusion**:

Each of the logical operators has unique characteristics. All have a vital role in the programming field. It is essential to understand and distinguish each.