+ 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.

10th Jul 2018, 4:28 PM
Youness Oubelkacem
Youness Oubelkacem - avatar
7 Antworten
+ 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
10th Jul 2018, 5:02 PM
Alexander Sokolov
Alexander Sokolov - avatar
+ 4
i've seen it being used in calculators i think but other that i have no clue
10th Jul 2018, 4:40 PM
Emperor Bob
Emperor Bob - avatar
+ 3
It evaluates codes or math expressions I think
10th Jul 2018, 4:52 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 3
I used eval in js to bring out the equality value in my simple calculators
10th Jul 2018, 6:06 PM
OLANIYI Babarinde Isola
OLANIYI Babarinde Isola - avatar
+ 2
yes it's very usefull in a calculator ... thanks anyway
10th Jul 2018, 4:47 PM
Youness Oubelkacem
Youness Oubelkacem - avatar
+ 2
thanks Alexander Sokolov for your clarification . but still wondring why this function is harmfull
10th Jul 2018, 5:18 PM
Youness Oubelkacem
Youness Oubelkacem - avatar
+ 1
its dangerous because people can use it to hack
10th Jul 2018, 7:33 PM
🅿️®️⭕️_e✖️e
🅿️®️⭕️_e✖️e - avatar