Logical Operators

 // LOGICAL AND - &&

let str = "ape";
if (str[0] == "a" && str.length > 3) {
  console.log("Good String");
} else {
  console.log("Not a good string");
}

// LOGICAL OR - ||
let num = 12;
if (num % 3 === 0 && (num + 1 === 15 || num - 1 === 12)) {
  console.log("safe");
} else {
  console.log("Not safe");
}

// LOGICAL NOT - !
let a = 8;
!(a < 6); //false
!(a > 10); //true


Comments

Popular posts from this blog

Callback Hell

TODO list with DOM

Refactoring callback hell code