+ 1
Code challenge question needed help ?
a question asked related to eval('2*2' + 4) which results in 48 any explanations ? why it's 48.
1 Respuesta
+ 8
lookie here
a b
x=("2*2"+4)
alert(x)
this alert produces 2*24
meaning the evaluation happened as follows:
first concatanate 2*2(a) and 4(b) to make a string of 2*24, then evaluate the string 2*24 to actually multiply 2 with 24
by the way
the following code in python produces same result
x=("2*2"+str(4))
print(x) # string of 2*24
print(eval(x)) # 48
[edit]
changed my explanation a bit
makes much more sense now
simple string concatenation (a+b) and then eval