How to use the ! Operator to negate a Boolean Value in JavaScript ?
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
Contact Us