Converting string "true" / "false" to boolean value [duplicate]

I have a JavaScript string containing "true" or "false".

How may I convert it to boolean without using the eval function?


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";