Converting string “true” / “false” to boolean value [duplicate]

Converting string “true” / “false” to boolean value [duplicate]

This question already has an answer here:

How can I convert a string to boolean in JavaScript?

74 answers

I have a JavaScript string containing “true” or “false”.
How may I convert it to boolean without using the eval function?

Solutions/Answers:

Solution 1:

var val = (string === "true");

Solution 2:

You could simply have: var result = (str == "true").

Solution 3:

If you’re using the variable result:

result = result == "true";

Related:  Create a simple 10 second countdown