The eval()
description says that, if the argument is an expression, it gets evaluated. If it's a statement, it gets executed. Well, why is it not getting executed then?
function calledf() {
alert("GF")
}
eval(calledf)
I would expect the function inside eval()
to get executed, yet it's not. Why?
If I assign the returned value to a variable, it gives me the JS statements, without being executed.
function calledf() {
alert("GF")
}
var exp = eval(calledf)
alert(exp)
Why?
Note: Yes, I know that without using the brackets ()
, a function returns the statements inside, but the description of eval()
says that, statements are being executed, and so, the returned statements should get executed. Is that not right?