I have a variable
var condition = "if(2 > 5)";
And sometime it will be
var condition = "if(3>5 && 4<2){quantity = 45;} else quantity=60;";
How I can compile these conditions, as these are in string variable?
It's dangerous to use because it can allow most anything to be injected into your code, but eval is the right thing to use here, if you really do have to have string evaluated to code.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
eval(condition)
eval()?