Logical Operators
👨💼 Sometimes we need to combine multiple conditions. Logical operators let us
build complex conditions from simpler ones.
The logical operators are:
&&AND - Both conditions must be true||OR - At least one condition must be true!NOT - Flips true to false, false to true
- Create variables:
isLoggedIn = true,isAdmin = false,age = 25 - Log whether user is logged in AND is admin
- Log whether user is logged in OR is admin
- Log whether user is NOT logged in
- Log whether age is greater than 18 AND less than 65
💰 Examples:
console.log(true && true) // true
console.log(true && false) // false
console.log(true || false) // true
console.log(!true) // false