I have a variable with instructions inside it, such as:
runThis= "alert(); if(1>2) { alert("NO WAY");}";
How do I run the code inside runThis?
If you really want to do this kind of thing, you can use the eval() function:
eval(runThis);
However this is not a recommended approach as it can lead to all kinds of difficult to diagnose bugs and errors
A better approach is to write a proper function with the code you wish to execute, and then assign it to a variable and invoke it via the variable:
//Assign function to variable
runThis = function(){
alert();
if(1>2) {
alert("NO WAY");
};
}
//Later, invoke the function
runThis();
evals I'd take a big hit, that's not fair for you. Removing.