How to declare a boolean in JavaScript?


To declare a Boolean in JavaScript, you need to assign true or false value.

var answer = true;

Example

To learn about the working of Boolean, let’s see the following example −

Live Demo

<html>
   <head>
      <title>JavaScript Boolean</title>
   </head>

   <body>
      <script>
         var num1 = 10;
         var num2 = 20;
         document.write(num1 > num2);
      </script>
   </body>
</html>

Updated on: 15-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements