DEV Community

Cover image for Clarity on logical operator js
Edeke Emmanuel
Edeke Emmanuel

Posted on • Updated on

Clarity on logical operator js

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

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

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

NOT gate:

The output is always opposite of the input in boolean expression.

Image description

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

NOR gate:

The output is always the opposite of the output of the OR gate.

Image description

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

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

Diagramatic operation of logic gates

Image description

Image description

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

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

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

Nullish coalescing operator ( ?? ):

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

Image description

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

Image description

Optional Chaining Operator ( ?. ):

The ?. operator returns undefined, if item or value in object is undefined or null, instead of throwing syntax error.

Image description

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");
Enter fullscreen mode Exit fullscreen mode

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

Let us connect with each other

connection between two or more parties bring solution to a problem

Github

LinkedIn

Twitter

Instagram

Facebook

ebakecode

Top comments (0)