Open In App

How to use the ! Operator to negate a Boolean Value in JavaScript ?

Last Updated : 29 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In JavaScript, you can use the ! (logical NOT) operator to negate a boolean value. The ! operator flips the truthiness of a value. If the operand is true, it becomes false, and if the operand is false, it becomes true.

Example: Here, !isTrue evaluates to false, and !isFalse evaluates to true.

Javascript




let isTrue = true;
let isFalse = false;
 
let negatedTrue = !isTrue;
let negatedFalse = !isFalse;
 
console.log(negatedTrue);  // Outputs false
console.log(negatedFalse); // Outputs true


Output

false
true


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads