Skip to content

Try our new Crash Courses!

Buy one of our new Crash Courses, now hosted on Podia.

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