ScanSkill

Logical NOT (!)

The logical NOT (!) operator reverses the value of the boolean. It is typically used with a boolean value.

Syntax

! operand

Example

const verified = !true;
console.log(verified); // Prints: false

let user;
if(!user) {
  console.log("No data present in the user variable");
}
// Prints: No data present in the user variable

let a = 2, b = 20;
if(!(a > b)) {
  console.log(`a: ${a} is NOT greater than b: ${b}`);
}
// Prints: a: 2 is NOT greater than b: 20

let doubleNot = !! true;
console.log(doubleNot);

The logical NOT (!) operator reverses the value of the operand. We can see in the above example that the stacked !! cancels the use of the NOT operator !.