“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.
//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
LANGUAGE | AND | OR | NOT |
C++ | && | || | ! |
C# | && | || | ! |
Java | && | || | ! |
JavaScript | && | || | ! |
PHP | && | || | ! |
Python | and | or | not |
Swift | && | || | ! |
Isomorphic Labs, a drug discovery start-up launched four years ago and owned by Google’s parent…
Regardless of whether TikTok faces a U.S. ban, Instagram is wasting no time positioning itself…
Amazon Web Services (AWS) continues to enhance its customer experience by offering more flexible payment…
JavaScript, often hailed as the "language of the web," continues to dominate the programming landscape…
Amazon is accelerating efforts to reinvent Alexa as a generative AI-powered “agent” capable of performing…
SpaceX's satellite-based Starlink, which is currently unlicensed for use in India, is reportedly being utilized…