0

I need to execute mathematical statements which is in string format in Javascript. For example:

"16 * 5" string should be execute like 16 * 5. Is there any build-in function to do this kind of execution? Is it possible to execute strings as command?

In other words, how to convert this string to an executable code?

  • 1
    if the string is supplied by random users online, DO NOT DO THIS, else `eval` was designed for this purpose. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval – Femi Oni Jan 25 '22 at 13:13

0 Answers0