Skip to main content

JavaScript: Logical Operators

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

Tags
Submitted by arilio666 on September 27, 2021

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.