How to download the sign of the multiplication of a variable and use it?

+operator1 / +operator2;

here's slash performing the function of division I in the variable "virazhenie". I need something like this +virazhenie operator1 +operator2. That is to take the division, multiplication, addition or subtraction depending on the value of a variable virazhenie. Tell me, like an easy task, but something I do not understand where to dig.
July 4th 19 at 23:59
2 answers
July 5th 19 at 00:01
Solution
eval(operator1+virazhenie+operator2)
July 5th 19 at 00:03
var ops = {
 '+': function(a, b) { return +a + +b; },
 '-': function(a, b) { return a - b; },
 '*': function(a, b) { return a * b; },
 '/': function(a, b) { return a / b; }
};

ops[virazhenie](operator1, operator2);
better than previous solutions? - Brendan_Hodkiewicz commented on July 5th 19 at 00:06
: eval is slow deoptimizer design, all the circuit containing the eval will not be optimized never
In addition, eval allows you to execute any code that makes it unsafe - geovanni_Hegmann commented on July 5th 19 at 00:09
Thanks, but in my case it is the perfect solution.
js.0su.su ;) - Brendan_Hodkiewicz commented on July 5th 19 at 00:12

Find more questions by tags HTMLJavaScript