Skip to content

Try our new Crash Courses!

Become a member using the button below to hide this banner and gain access to our new Crash Courses.

Logical NOT operator – JavaScript

Length: 10 minutes

Details

The logical NOT operator flips the value of a boolean. If the value is true, the NOT operator returns false. If the value is false, the NOT operator returns true.

NOT true

if (!true) {
  console.log('This will not run because !true returns false');
}

In the example above, the line inside the if statement will not run because !true returns false.

NOT false

if (!false) {
  console.log('This will run because !false returns true');
}

In the example above, the line inside the if statement will run because !false returns true.

Demo

Exercises

Try the 2 code snippets from the Details section in the console.

Reference

Logical NOT on MDN

Back to: JavaScript Reference > JS Conditional Statements