Open In App

Convert boolean result into number/integer in JavaScript

    A JavaScript boolean represents one of two values: true or false.
    However, if one wants to convert a variable that stores boolean value, into integer “0” or “1”, they can do so using multiple approaches. We will look into some of them in this article.

    The most popular methods are:



  1. Using ternary or conditional operator
  2. Using unary + operator.
  3. Using bitwise And (&) or bitwise Or ( | ) operator.
  4. Using Number() function. It converts data type to number.

Article Tags :