+ 5
Eval function in javascript
any ideas about eval function in js ? because it seems very usefull but some says that it can be harmfull can someone explain this.
7 Answers
+ 4
Hello, Youness Oubelkacem !
In the simplest case, eval just executes the code, for example:
var a = 1;
(function() {
var a = 2
eval('alert(a)');
// 2
}) ()
But he can not only execute the code, but also return the result.
The eval call returns the last calculated expression, for example:
alert(eval('1 + 1')); // 2
+ 4
i've seen it being used in calculators i think but other that i have no clue
+ 3
It evaluates codes or math expressions I think
+ 3
I used eval in js to bring out the equality value in my simple calculators
+ 2
yes it's very usefull in a calculator ...
thanks anyway
+ 2
thanks Alexander Sokolov for your clarification .
but still wondring why this function is harmfull
+ 1
its dangerous because people can use it to hack