JavaScript is_bool
Returns true if variable is a boolean
1 2 3 4 56 7 8 9 1011 12 | function is_bool (mixed_var) { // Returns true if variable is a boolean // // version: 1109.2015 // discuss at: http://phpjs.org/functions/is_bool // + original by: Onno Marsman // * example 1: is_bool(false); // * returns 1: true // * example 2: is_bool(0); // * returns 2: false return (typeof mixed_var === 'boolean'); } |
Examples
» Example 1
Running
1 | is_bool(false); |
Should return
1 | true |
» Example 2
Running
1 | is_bool(0); |
Should return
1 | false |
Dependencies
No dependencies, you can use this function standalone.
Open syntax issues
php.js uses JsLint to help us keep our code consistent and prevent some common bugs.
Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.
Authors
Thanks to the following developers, you get to have is_bool goodness in JavaScript.

CoursesWeb
Apr 30th
For is_bool, i use:
function is_bool(obj) { return (obj === true || obj === false); }