Computer >> Computer tutorials >  >> Programming >> Javascript

How can I convert a string to boolean in JavaScript?


Yes, it is possible to convert a string to Boolean.

Example

You can try to run the following code to achieve this −

<html>
   <head>
      <title>JavaScript Boolean</title>
   </head>
   
   <body>
      <script>
         var answer = true;
         document.write(answer);

         var result = (answer == 'true');
         document.write("<br>"+result);
      </script>
   </body>
</html>