Skip to content

Toggle a boolean value in JavaScript

If your variable is of boolean type:

let stopVehicle = false;
console.log(!stopVehicle);
//true
Advertisements

If your variable is of string type:

let stopVehicle = 'true';
console.log(stopVehicle == 'true'? 'false':'true')
//false

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.