I wanna basically execute a statement stored in a var. For example, I have this,
var statement = "alert('Hi!')";
How can I make JS execute the statement stored inside the var statement? Thanks a lot guys.
I wanna basically execute a statement stored in a var. For example, I have this,
var statement = "alert('Hi!')";
How can I make JS execute the statement stored inside the var statement? Thanks a lot guys.
This will do it, but it's not recommended
var statement = "alert('Hi!')";
eval(statement)
You should be able to use eval()
like this:
var statement = 'alert('Hi!');";
eval(statement);
eval is a dangerous thing though and should be used with caution.