+ 5

Why do we still learning eval() in JavaScript, here on Sololearn?

I saw this eval() related questions in a JavaScript challenge : var x = "2 * 2"; var y = 4; var z = eval( x + y) ; alert(z) // 48 as result When I tried this by my self on my pc. It says, EvalError: call to eval() blocked by CSP (Content Security Policy). I'm seeing this eval function too frequently in quizzes, My question is if this eval is depreciated by most of the modern browsers for the sake of security issues. Then what benefits we will get by learning it here. Even it is not practical in my opinion. Elaborate on this if I'm wrong.

1st Dec 2019, 8:51 PM
3rdMOLAR 🐙
3rdMOLAR 🐙 - avatar
3 odpowiedzi
+ 3
From the JavaScript fundamental I learn that eval() could be used for evaluation of the JavaScript statements from the strings. For example : var x = "12" // type of string eval(x) // returns 12 as type of number. var x = "alert('hello world')" ; eval(x) // calls an alert, says 'hello world' ; I don't see any benefits of it regarding anything else. And my question remains on its vulnerability issue is the same as it was. It would be more helpful if someone shows me how It would be helpful in the real world practices.
2nd Dec 2019, 8:37 AM
3rdMOLAR 🐙
3rdMOLAR 🐙 - avatar
0
Hi
3rd Dec 2019, 6:12 PM
Hassan Bilha
Hassan Bilha - avatar
0
Hi
3rd Dec 2019, 6:22 PM
Hassan Bilha
Hassan Bilha - avatar