Converting string "true" / "false" to boolean value

user160820 picture user160820 · Oct 20, 2010 · Viewed 253.5k times · Source

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

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

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · Oct 20, 2010
var val = (string === "true");