+ 3
Eval function in js
How does it actually work var a="1"; var b="2*2"; console.log(eval(a+b)); Output 24 If a=3 Output 64 Plz explain how eval works in case of values in strings like above example...
4 Respostas
+ 11
Eval evaluates a JavaScript expression just like it would actually stand at this point.
eval(a+b) will be processed as
eval("1"+"2*2")
both strings are added now so it'd look like
eval("12*2")
now the string will be evaluated:
12*2 = 24
if a=3:
eval(3+"2*2") is equal to
eval("32*2") which results in
32*2 = 64
+ 2
Thanks ! I was lost too 🤯😁
+ 1
Thankyou
+ 1
Good result