boolean in js code example

Example 1: javascript sort boolean value

a = [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false];
    
    
    a.sort(function(x, y) {
        // true values first
        return (x === y)? 0 : x? -1 : 1;
        // false values first
        // return (x === y)? 0 : x? 1 : -1;
    });
    
    console.log(a);

Example 2: js is boolean

if (typeof variable === "boolean"){
  // variable is a boolean
}

Example 3: change true to false js

var thing = true; //try changing this to false
thing = !thing; //the variable will go from true to false, or from false to true

Example 4: javascript true string to boolean

var isHidden='true';
var isHiddenBool = (isHidden == 'true');