How to use Boolean in JavaScript

In this article I am going to explain about Boolean object in JavaScript.
  • 2447

JavaScript Boolean object

In JavaScript Boolean object use to convert Non Boolean value in Boolean value. Boolean value means its represent only true and false. There are some method and properties of Boolean object by which we can perform work. There are following:-

Boolean object properties

  • Constructor - Its return function by which create Boolean prototype.
  • Prototype - Add properties and method to Boolean object.

Boolean object method

  • toString - Convert Boolean value in string format.
  • valueOf() - Its return the primitive value of Boolean object.

How to convert Non Boolean value in Boolean format.

<html>

<head>

    <script type="text/javascript">

        function Myfun() {

            var bool = new Boolean(1);

            var myvar = bool.toString();

            alert(myvar);

        }

    </script>

</head>

<body>

    <button onclick="Myfun()">

        Click</button>

</body>

</html>

 

Output

boolean.gif
 

 Further Readings

You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.