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