

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check if a variable is boolean in JavaScript?
To check if a variable is Boolean in JavaScript, use the typeof operator.
Example
You can try to run the following code to check for a Boolean variable −
<html> <head> <title>JavaScript Boolean</title> </head> <body> <script> var answer = true; if(typeof(answer) === "boolean") { alert("Boolean"); } else { alert("Not a Boolean"); } </script> </body> </html>
- Related Questions & Answers
- How to check if a variable is NaN in JavaScript?
- How to check if a variable is an integer in JavaScript?
- How to check if a variable is an array in JavaScript?
- How to check if a variable exists in JavaScript?
- How can I check if a JavaScript variable is function type?
- How do you check if a variable is an array in JavaScript?
- Python - Check if a variable is string
- How to check if a variable is NULL in C/C++?
- How to check if String value is Boolean type in java?
- Check if variable is tuple in Python
- How to check if type of a variable is string in Python?
- In MySQL stored procedures, how to check if a local variable is null?
- How to check if a JavaScript function is defined?
- Can I verify if a JavaScript variable is loaded if so, how?
- How to check if a document is ready in JavaScript?
Advertisements