How to toggle a boolean in JavaScript

2 Answers

0 votes
let bool = true;

bool = !bool;
console.log(bool);

bool = !bool;
console.log(bool);

bool = !bool;
console.log(bool);

bool = !bool;
console.log(bool);
  
  
  
  
/*
run:

false
true
false
true
  
*/

 



answered May 9, 2022 by avibootz
0 votes
console.log(!true); 
console.log(!false); 

  
  
  
  
/*
run:

false
true
  
*/

 



answered May 9, 2022 by avibootz

Related questions

...