Search code examples
javascriptnumbersintegerbooleantype-conversion

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?


Solution

  • Javascript has a ternary operator you could use:

    var i = result ? 1 : 0;