-1

My string is 10+20/3*87/234 how can I calculate the result without using eval function in javascript?

2

1 Answer 1

0

You can use function constructor https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function

function calculate(fn) {
  return new Function('return ' + fn)();
}


alert(calculate('10+20/3*87/234'));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.