Skip to content
Related Articles

Related Articles

How to convert Number to Boolean in JavaScript ?

Improve Article
Save Article
  • Last Updated : 08 Jan, 2021
Improve Article
Save Article

We convert a Number to Boolean by using the JavaScript Boolean() method. A JavaScript boolean results in one of the two values i.e true or false. However, if one wants to convert a variable that stores integer “0” or “1” into Boolean Value i.e “true” or “false”. 





<!DOCTYPE html>
        <h1 style="color:green">
            Click the button to change the
            number value into boolean.
        <button onclick="myFunction()">Change</button>
        <p>The number value of the variable is :</p>
        <p id="result"></p>
            // Initializing boolvalue as true 
            var numvalue = 1;
            // JavaScript program to illustrate boolean 
            // conversion using ternary operator 
            function myFunction() {
                    .innerHTML = Boolean(numvalue);

Note: If the above Boolean() method is called as Boolean(!numvalue), it shows the result as “false“. Similarly if it is called as Boolean(!!numvalue), it gives the result as “true“.


Before clicking on button:

After clicking on button:

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!