quote:
Originally posted by markee
quote:
Originally posted by phalanxii
I believe Math.abs(<boolean>) also does that.
This will give the absolute value of the number which is not what you want. Boolean expressions are equivalent to 1 for true, 0 for null and -1 for false and thus you would have a problem where you couldn't tell the difference between true and false. Even Spunky's code is incorrect because it misses the null possibility and false should be negate one not zero. The proper methods would be either to use the parseInt method or multiply the boolean variable by 1 (or minus zero). This is also the same when you try to convert a string to a number.
....multiplying -1 by 1 wouldn't produce 0 as he wanted, under your logic. false is equal to 0.