Logical Operators | Bondar Academy
Course: JavaScript for Testers
Module: JavaScript Fundamentals
Instructor: Artem Bondar
Lesson Summary
This lesson covers logical operators , which are essential for processing logical expressions in programming. The primary logical operators discussed are AND , OR , and NOT . Logical AND Operator The AND operator, represented by && , combines two or more logical expressions. The entire expression evaluates to true only if all individual expressions are true . For example: console.log(true && true); // Outputs: true console.log(true && false); // Outputs: false Logical OR Operator The OR operator, denoted by || , evaluates to true if at least one of the expressions is true . For instance: console.log(true || false); // Outputs: true console.log(false || false); // Outputs: false Real-World Example Consider a scenario where we check if a user is eligible for a driver’s license. The criteria are: The user must be a US citizen . The user must be over 18 years old . The logical expression for eligibility can be constructed using the AND operator: let isEligible = (age > 18 && isUSCitizen); Logical NOT Operator The NOT operator, represented by ! , inverts the truth value of an expression. For example: console.log(!true); // Outputs: false console.log(6 != 10); // Outputs: true Summary In summary: AND : && - All values must be true. OR : || - Any value must be true. NOT : ! - Inverts the truth value. These operators are fundamental for building logical expressions in programming.