Many programmers say it is a bad practice to use the eval() function:
When is JavaScript's eval() not evil?
Eval is actually a powerful feature and there are some things that are impossible to do without it. For example:
my_result = get_script_result("foo.js")), the only way of programming the function get_script_result is by using eval inside it.And anything else you'd want to do that involves creating code on the fly.
The reason it is considered "evil" is because it's classicaly used by novices to do things that the language can handle natively. For example, the code below:
age_of_erick = 34;
age_of_john = 21;
person = "erick";
eval("console.log('age_of_"+person+"')");
And the code below:
age = {erick:34, john:21};
person = "erick";
console.log(age["erick"]);
Both do the same thing, except one parses a string, generates code from it, compiles into machine code and then runs, while the other reads a value from a hash, which is a lot faster.