How to use the ! Operator to negate a Boolean Value in JavaScript ?
Last Updated :
29 Jan, 2024
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);
console.log(negatedFalse);
|
Share your thoughts in the comments
Please Login to comment...