I have a variable that stores false or true, but I need 0 or 1 instead, respectively. How can I do this?
I prefer to use the Number function. It takes an object and converts it to a number.
Example:
var myFalseBool = false;
var myTrueBool = true;
var myFalseInt = Number(myFalseBool);
console.log(myFalseInt === 0);
var myTrueInt = Number(myTrueBool);
console.log(myTrueInt === 1);
You can test it in a jsFiddle.