hd. hd. - 8 days ago 6
Javascript Question

Convert boolean result into number/integer

I have a variable that stores

false
or
true
, but I need
0
or
1
instead, respectively. How can I do this?

Answer

Javascript has a ternary operator you could use:

var i = result ? 1 : 0;