Simple boolean toggling
Two JavaScript functions for simple boolean toggling.
JavaScript
var fn_toggleBoolean=function(q_a){
return Boolean(Math.abs(Number(q_a)-1));
};
/**
* fn_toggleBoolean(true)===false
* fn_toggleBoolean(false)===true
*
* Thus:
* fn_toggleBoolean(fn_toggleBoolean(true))===true
*/
/**
* Another way
*/
var fn_toggleBoolean_b=function(q_a){
return q_a==true ? false : true;
};
/**
* Okay okay. The second way looks much simpler
* but the first one is the most elegant one,
* isn't it? :D
*/