JavaScript has a bunch of built-in tricks to make coding easier. One of these tricks is the eval() function, which takes a string and executes it as if it were a JavaScript expression. I actually talked about eval a little bit in Part I, Day 5, but here's a little example for you to review:
var the_unevaled_answer = "2 + 3";
var the_evaled_answer = eval("2 + 3");
alert("the un-evaled answer is " + the_unevaled_answer + " and the evaled answer is " + the_evaled_answer);
If you run this silly eval code, you'll see that it actually executes the string "2 + 3" in JavaScript. So, when you set the_evaled_answer equal to
eval("2 + 3"), JavaScript figures out and then returns the sum of two and three.
This may seem like a silly thing to do, but it can get way more interesting. For example, you can use eval to create functions entirely on the fly, based on user input. This could be used to make programs that actually alter themselves over time. They could evolve, mutate, become sentient, maybe even take over the world. In practice, eval is rarely used, but you might see people using it to access hard-to-reach objects.