programming

Logical Operators

“Programs must be written for people to read, and only incidentally for machines to execute.”

Harold Abelson, Structure and Interpretation of Computer Programs

Logical operators are generally symbols or words which connect two or more expressions that allow a program to make a decision based on a given set of conditions.

Logical operators usually control the program flow and are frequently used with the if, while, or some other control statement.

Three (3) Types Logical Operators

  1. Logical AND operator (&&): For logical AND operators, both conditions must be true for the statement to be true. If one of them is false, then the program will return false.
//Example
let a, b;
a = 3; b = 4;
console.log(a === 3 && b === 4) //TRUE
console.log(a === 3 && b === 3) //FALSE

2. Logical OR operator ( || ): For logical OR operators, one of the operands just have to be true for the statement to be true.

//Using variables from our first example
console.log(a === 3) || (b === 4) //TRUE
console.log(a === 3) || (b === 3) //TRUE

3. Logical NOT operator ( ! ): This is used to reverse the logical state of its operands. If a condition is true, then the Logical Not will make it false.

//Using variables from our previous example
console.log(!(a === 3)) //FALSE
LANGUAGEANDOR NOT
C++&&||!
C#&&||!
Java&&||!
JavaScript&&||!
PHP&&||!
Pythonandornot
Swift&&||!

Recent Posts

South Korea bans downloads of DeepSeek AI until further notice

The South Korean government announced on Monday that it had temporarily halted new downloads of…

5 days ago

Which programming language is best for software development?

As a software developer, choosing the right programming language for software development can be a…

1 week ago

What is a server farm?

A server farm, also known as a server cluster or data center, is a collection…

1 week ago

Elon Musk’s Starlink satellite internet service is awaiting authorization to begin operations in Pakistan.

Pakistan's mobile and broadband internet speeds rank in the bottom 10 percent globally, according to…

2 weeks ago

React Native Styling Guide

React Native is a popular framework for building cross-platform mobile applications using JavaScript and React.…

2 weeks ago

You can now customize your Android home screen shortcut with any widget of your choice

Google is not only passionate about developing innovative apps and services but also about finding…

2 weeks ago