Clarity on logical operator js
Tags: webdev, javascript, programming, beginners
Published: 2023-03-24 18:41:40


Logical Operator JavaScript(LOJ) is very much familiar with logic gate, if you are computer scientist or mathematician, this will be friendly with you. <u>Nevertheless I am not one, so meaning you can understand it too.</u>

_The main focus will be on LOJ but let check out brief explanation on logic gate._

# Logic gates
logic gate is the principle of any digital system. It used to perform logical operations on single or multiple binary inputs and return(result) one binary output.

> This is a basic concept in the studies of electronic and digital service mainly based on the concept of boolean function.

## Types of logic gate
Computer is program to understand only boolean function or binary system; which are only 0 (False or No) and 1 (True or Yes).

### 1. AND gate:
In the result or output, it always return **False** (0) but if both the input are True (1), then the output is **True**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/84gf39x33a7mxzzyjzpx.jpg)

### OR gate:
In the output, it always return **True** (1) but if both the input are False (0), then the output is **False**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4enjhhdv6txestpmd3ux.jpg)

### NOT gate:
The output is always opposite of the input in boolean expression.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gxebr7r2pddxyv3ypbe6.jpg)

> combine gate is the joining of many gate together, which are:

#### NAND gate:

---
The output is always the opposite of the output of the AND gate.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ilwab8yxuu8psp7vu2j2.jpg)

#### NOR gate:
The output is always the opposite of the output of the OR gate.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aq74qzmsn85pafdm92eh.jpg)

##### XOR gate:
In the output, it always return True but if both the input are either False or True, then the output is False. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7f6p4ccihhfxhrs4ifu.jpg)

##### XNOR gate:
In the output, always return False but if both the input are either False or True, then the output is True.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/plvlpenqilkke83zbs2m.jpg)

Diagramatic operation of logic gates

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/imwzzkaxlvq63dpvo5a7.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/547ggpmtyoafdjh1f6t5.jpeg)

# Logical operator js
JavaScript Logical operator allows us to compare the expressions/arguments/statements between variables or values.

It can also be used to control a boolean or set termination conditions for loops.

## Types of logical operator js
### - And operator ( && )
:
The `&&` operator compares two expressions. If the first is express as true value, the result will be the value of the second expression. If the first is express as false value, the result will be the value of the first expression.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rw60zz94c6ano9ebgy8c.png)

This simply means always return `false` except both condition are true.

### Or operator ( || ):
The `||` operator compares two expressions. If the first is express as false value, the result will be the value of the second expression. If the first is express as true value, the result will be the value of the first expression.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s9768nw5c3v7ylha9p8l.png)

This simply means always return `true` except both condition are false.

### Not operator ( ! ):
The `!` operator always return (output) the inverse of the argument of either false or true value.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fu0umfyhft5a2d7l7vxc.png)

### Nullish coalescing operator ( ?? ):
The `??` operator always return the first argument (that is define), if it is not null or undefined.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqvdg8al6kgrs6h1n4up.png)

The difference between `??` and `||` is that the `??` returns the first define value while `||` returns the first true value.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q486j9gli2twi84a96xm.png)

### Optional Chaining Operator ( ?. ):
The `?.` operator returns undefined, if item or value in object is undefined or null, instead of throwing syntax error.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lxvcrhy0k6eifsh5gnu0.png)

In precedence And operator `&&` is higher than Or operator `||`.

~~Is coding hard ?~~

```
console.log("coding is easy with support from community and great articles like mine");
```
> Coding is a process, needs time, dedication and continual practices (keep doing projects), then you are at the peak of perfection.

[Furthermore explanation on logic gate
](https://www.tutorialspoint.com/computer_logical_organization/logic_gates.htm)

## Let us connect with each other

> connection between two or more parties bring solution to a problem 

[Github](https://github.com/edekeemmanuel/)

[LinkedIn](https://www.linkedin.com/in/ebakecode/)

[Twitter](https://twitter.com/EBakeCode)

[Instagram](https://instagram.com/ebakecode)

[Facebook](https://facebook.com/ebakecode)

[ebakecode](https://ebakecode.web.app/)