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&&||!

Author

Recent Posts

Implementing Code Splitting in React with React.lazy

As your React applications grow in size, performance can become an issue, especially when dealing…

1 day ago

Understanding React.js Context API

React.js is widely known for its component-based architecture, where data flows from parent to child…

2 days ago

React’s Suspense and Concurrent Mode: A Comprehensive Guide

React's Suspense and Concurrent Mode represent two of the most exciting advancements in React, designed…

2 days ago

Using React.useEffect for Data Fetching

Introduction React's useEffect hook is a powerful tool for managing side effects in functional components.…

5 days ago

Understanding PHP’s Autoload Functionality

Introduction As PHP projects grow in complexity, managing dependencies and ensuring that all necessary classes…

5 days ago

Error Boundaries in React.js: A Comprehensive Guide

In modern web development, user experience is paramount. A critical aspect of maintaining a smooth…

5 days ago