Hello,
how to evaluate for example this string expression “2-4+10” without using eval().
Thanks.
Hello,
how to evaluate for example this string expression “2-4+10” without using eval().
Thanks.
What have you tried so far?
I read a lot of articles in which we say if a string represents an expression, eval () evaluates this expression. but has security risks.
I discovered this function
parse(obj) {
return Function(’“use strict”;return (’ + obj + ‘)’)();
}
that does the job.