When is JavaScript’s eval() not evil?

I’m writing some JavaScript code to parse user-entered functions (for spreadsheet-like functionality). Having parsed the formula I could convert it into JavaScript and run eval() on it to yield the result.

However, I’ve always shied away from using eval() if I can avoid it because it’s evil (and, rightly or wrongly, I’ve always thought it is even more evil in JavaScript, because the code to be evaluated might be changed by the user).

So, when it is OK to use it?

26 Answers
26

Leave a Comment