How can I convert a string to boolean in JavaScript?

JavascriptWeb DevelopmentFront End Technology

<p style="">Yes, it is possible to convert a string to Boolean.</p><h2>Example</h2><p style="">You can try to run the following code to achieve this &minus;</p><p style=""><a href="" rel="nofollow noopener noreferrer" target="_blank">Live Demo</a></p><pre class="prettyprint notranslate">&lt;html&gt; &nbsp; &nbsp;&lt;head&gt; &nbsp; &nbsp; &nbsp; &lt;title&gt;JavaScript Boolean&lt;/title&gt; &nbsp; &nbsp;&lt;/head&gt; &nbsp; &nbsp; &nbsp; &nbsp;&lt;body&gt; &nbsp; &nbsp; &nbsp; &lt;script&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var answer = true; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.write(answer); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var result = (answer == &#39;true&#39;); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.write(&quot;&lt;br&gt;&quot;+result); &nbsp; &nbsp; &nbsp; &lt;/script&gt; &nbsp; &nbsp;&lt;/body&gt; &lt;/html&gt;</pre>
Updated on 15-Jun-2020 07:10:00