How to check if type is boolean in JavaScript

2 Answers

0 votes
const bool = true;

if (typeof bool === 'boolean') {
  	console.log('boolean');
} else {
  	console.log('not boolean');
}


  
  
  
/*
run:
  
"boolean"
  
*/

 



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


  
  
  
/*
run:
  
"boolean"
"boolean"
  
*/

 



answered May 26, 2022 by avibootz

Related questions

2 answers 123 views
2 answers 136 views
1 answer 141 views
1 answer 119 views
1 answer 188 views
2 answers 207 views
1 answer 135 views
135 views asked Dec 27, 2022 by avibootz
...