+ 3

eval ()

need help! who can explain step by step var a = "2*3"; var b = 5; var c = eval(b+a); document.write(c);

1st Feb 2017, 5:23 AM
Didi Georgel Danaila
Didi Georgel Danaila - avatar
6 Respuestas
+ 8
(Really??…)
1st Feb 2017, 12:53 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 7
eval() executes a string as pure javascript. (c = 5 + 2 * 3)
1st Feb 2017, 5:31 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 5
In fact, eval(expr) firstly evaluate the expression passed in argument, and secondly eval the string, if the argument resulting is a string ( else return the argument unchanged ). So, argument in this case is b+a, wich is equal to "52*3" ( concanetation of "5" et "2*3" ), that's count 156 ^^
1st Feb 2017, 6:31 AM
visph
visph - avatar
+ 2
@visph is correct, 156.
1st Feb 2017, 6:36 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 2
thanks guys
1st Feb 2017, 6:49 AM
Didi Georgel Danaila
Didi Georgel Danaila - avatar
+ 1
156?
1st Feb 2017, 6:20 AM
Didi Georgel Danaila
Didi Georgel Danaila - avatar