How to declare boolean variables in JavaScript?


A boolean variable in JavaScript has two values True or False.

Example

You can try to run the following code to learn how to work with Boolean variables −

<!DOCTYPE html>
<html>
   <body>
      <p>35 > 20</p>
      <button onclick="myValue()">Click for result</button>
      <p id="test"></p>
      <script>
         function myValue() {
            document.getElementById("test").innerHTML = Boolean(35 > 20);
         }
      </script>
   </body>
</html>

Updated on: 13-Jun-2020

443 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements