JavaScript: Logical Operators

Profile picture for user arilio666

So to do something or ask a programming language to do something, we cannot tell it by plain English. Instead, there is a way called writing logic to the variables and values, asking them to do something and validate this or that etc.

1) && (And Operator)

So this Operator performs the logic of 'and', which is precisely what it means. It generally says take two values of a variable and find whether they are equal, more minor, more significant, etc.

x = 500;
z = 200;

if(x > z && z < x){
console.log("x is probably bigger")
}else{
console.log("logic failed")
}

Output: x is probably bigger

2) || (Or Operator)

This does the operation like either this or that needs to satisfy the logic which is sufficient enough.

x = 500;
z = 200;

if(x < z || z < x){
console.log("lOGIC SATISFIED FOR ||")
}else{
console.log("logic failed")
}

Output: lOGIC SATISFIED FOR ||

3) ! (Not)

It tells the values should not do specific function or should be equal, greater or lesser etc.

x = 500;
z = 200;

if(!(z <= x)){
console.log("lOGIC SATISFIED FOR !")
}else{
console.log("logic failed")
}

Output: logic failed