+ 2

Var x = '2*2'; var y = 4 ; var z = eval(x+y) ;alert(z); why the answer =48 ? Can anyone explain it?

Help

4th Feb 2020, 12:20 PM
Ibrahim Idrees
Ibrahim Idrees - avatar
2 Antworten
+ 5
x+y is executed first. y is treated as string, because x is one, so the resulting string is '2*24' eval('2*24') is 48.
4th Feb 2020, 12:39 PM
HonFu
HonFu - avatar
+ 1
Got it ! Thanks so much
4th Feb 2020, 1:49 PM
Ibrahim Idrees
Ibrahim Idrees - avatar