That's what typeof is there for. The parentheses are optional since it is an operator.

if (typeof variable == "boolean") {
    // variable is a boolean
}
Answer from Amit Joki on Stack Overflow
Top answer
1 of 16
843

That's what typeof is there for. The parentheses are optional since it is an operator.

if (typeof variable == "boolean") {
    // variable is a boolean
}
2 of 16
86

With pure JavaScript, you can simply use typeof and do something like typeof false or typeof true and it will return "boolean"...

But wait, that's not the only way to do that, I'm creating functions below to show different ways you can check for Boolean in JavaScript, also different ways you can do it in some new frameworks, let's start with this one:

function isBoolean(val) {
   return val === false || val === true;
}

Or one-line ES6 way ...

const isBoolean = val => 'boolean' === typeof val;

and call it like!

isBoolean(false); //return true

Also in Underscore source code they check it like this(with the _. at the start of the function name):

isBoolean = function(obj) {
   return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
};

Also in jQuery you can check it like this:

jQuery.type(true); //return "boolean"

In React, if using propTypes, you can check a value to be boolean like this:

MyComponent.propTypes = {
  children: PropTypes.bool.isRequired
};

If using TypeScript, you can use type boolean also:

let isDone: boolean = false;

Also another way to do it, is like converting the value to boolean and see if it's exactly the same still, something like:

const isBoolean = val => !!val === val;

or like:

const isBoolean = val => Boolean(val) === val;

and call it!

isBoolean(false); //return true

It's not recommended using any framework for this as it's really a simple check in JavaScript.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › typeof
typeof - JavaScript - MDN Web Docs - Mozilla
(logical NOT) operator are equivalent to Boolean() // Symbols typeof Symbol() === "symbol"; typeof Symbol("foo") === "symbol"; typeof Symbol.iterator === "symbol"; // Undefined typeof undefined === "undefined"; typeof declaredButUndefinedVariable === "undefined"; typeof undeclaredVariable === "undefined"; // Objects typeof { a: 1 } === "object"; // use Array.isArray or Object.prototype.toString.call // to differentiate regular objects from arrays typeof [1, 2, 4] === "object"; typeof new Date() === "object"; typeof /regex/ === "object"; // The following are confusing, dangerous, and wasteful. Avoid them. typeof new Boolean(true) === "object"; typeof new Number(1) === "object"; typeof new String("abc") === "object"; // Functions typeof function () {} === "function"; typeof class C {} === "function"; typeof Math.sin === "function"; js ·
🌐
W3Schools
w3schools.com › js › js_booleans.asp
JavaScript Booleans
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Bootcamp JS Certificate JS Reference ... The Boolean value of an expression is the basis for all JavaScript comparisons and conditions.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Boolean
Boolean - JavaScript - MDN Web Docs
js · // Do this: // This always returns a boolean value const isObject = (obj) => !!obj && typeof obj === "object"; // Or this: const isObject = (obj) => Boolean(obj) && typeof obj === "object"; // Or this: const isObject = (obj) => obj !== null && typeof obj === "object"; // Instead of this: // This may return falsy values that are not equal to false const isObject = (obj) => obj && typeof obj === "object"; For converting non-boolean values to boolean, use Boolean as a function or use the double NOT operator.
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-array-typeof
JavaScript Typeof for Data Types: Array, Boolean and More | Built In
Checking for Boolean values is easy. They are going to be either true or false, and the typeof a boolean returns "boolean":
🌐
W3Schools
w3schools.com › js › js_typeof.asp
JavaScript typeof
The typeof operator returns the data type of a JavaScript variable. In JavaScript, a primitive value is a single value with no properties or methods. ... The typeof operator returns the type of a variable or an expression. typeof "John" // Returns ...
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript boolean
JavaScript Boolean vs. boolean: Explained By Examples
October 6, 2023 - let a = Boolean('Hi'); console.log(a); // true console.log(typeof(a)); // booleanCode language: JavaScript (javascript)
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Boolean › Boolean
Boolean() constructor - JavaScript - MDN Web Docs
July 10, 2025 - js · const bZero = new Boolean(0); const bNull = new Boolean(null); const bEmptyString = new Boolean(""); const bfalse = new Boolean(false); typeof bfalse; // "object" Boolean(bfalse); // true · Note how converting a Boolean object to a primitive with Boolean() always yields true, even if the object holds a value of false.
🌐
Programiz
programiz.com › javascript › booleans
JavaScript Booleans
const a = true; // creating a boolean object const b = new Boolean(true); console.log(a); // true console.log(b); // true console.log(typeof a); // "boolean" console.log(typeof b); // "object"
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript boolean type
JavaScript Boolean Type
November 15, 2024 - The JavaScript boolean primitive type has two literal values: true and false.
🌐
TypeScript
typescriptlang.org › docs › handbook › 2 › typeof-types.html
TypeScript: Documentation - Typeof Type Operator
This isn’t very useful for basic types, but combined with other type operators, you can use typeof to conveniently express many patterns. For an example, let’s start by looking at the predefined type ReturnType<T>. It takes a function type and produces its return type: ts · type · Predicate = ( x: unknown) => boolean; type ·
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-check-if-type-boolean
How to check if type is Boolean using JavaScript | bobbyhadz
March 3, 2024 - Use the `typeof` operator to check if a value is of boolean type. The `typeof` operator will return `"boolean"` if the type of the value is boolean.
🌐
JavaScript in Plain English
javascript.plainenglish.io › how-to-check-for-a-boolean-in-javascript-98fdc8aec2a7
How to Check for a Boolean in JavaScript | by Dr. Derek Austin 🥳 | JavaScript in Plain English
January 4, 2023 - Checking for boolean values is easy in JavaScript— they are going to be either true or false, and typeof a boolean is always "boolean".
🌐
TutorialsTeacher
tutorialsteacher.com › javascript › javascript-boolean
JavaScript Booleans (Primitive Type and Object)
The new Boolean() will return a Boolean object, whereas it returns a boolean without the new keyword. The boolean (lower case) is the primitive type, whereas Boolean (upper case) is an object in JavaScript. Use the typeof operator to check the types.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-boolean
JavaScript Boolean - GeeksforGeeks
July 11, 2025 - let obj = new Boolean(false); ... is generally discouraged because it can lead to confusion. A Boolean primitive is a simple representation of true or false....
🌐
W3Resource
w3resource.com › javascript › operators › typeof.php
JavaScript : typeof operator - w3resource
September 30, 2023 - > typeof false "boolean" > typeof true "boolean" Examples of typeof operator: function · Console · > typeof Math.tan "function" >typeof function(){} "function" Examples of typeof operator: object · Console · > typeof {a:1} "object" > typeof new Date() "object" > typeof null "object" > typeof /a-z/ "object" > typeof Math "object" > typeof JSON "object" Examples of typeof operator: undefined ·
🌐
Medium
medium.com › theleanprogrammer › javascript-typeof-228ed8e296d5
The Javascript “typeof” Operator
June 1, 2021 - typeof true === ‘boolean’; typeof false === ‘boolean’; typeof Boolean(1) === ‘boolean’; // Boolean() will convert values based on if they’re truthy or falsy typeof !!(1) === ‘boolean’; // two calls of the !
🌐
Codidact
software.codidact.com › posts › 291489 › 291490
In javascript is there really a good reason to never check for boolean true || false such as if(var){}else{}? - Software Development
Anyway, you must define exactly what you need: check if the type is boolean, or if the type-coerced value is true/false, or anything else (ignore null and undefined, or empty arrays can't be true, etc). Then you change the code accordingly. IMO, if (typeof(someVar) !== 'undefined' || typeof(someVar) !== null || someVar !== '') is not a good way to check boolean values.
🌐
TutorialsPoint
tutorialspoint.com › javascript › javascript_typeof_operator.htm
JavaScript - typeof Operator
The tyepof operand returns boolean for boolean variables. typeof true; //returns "boolean"; typeof false; //returns "boolean"; typeof Boolean(10); //returns "boolean";