How can I convert a string to boolean in JavaScript?

JavascriptWeb DevelopmentFront End Technology

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

Example

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

Live Demo

<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>
raja
Published on 18-Jan-2018 17:27:57
Advertisements