+ 9
Eval into js
Why does eval do it?
8 Antworten
+ 8
Пoчему eval так ведет себя в js?
https://code.sololearn.com/Wj8d1SU8TPX9/?ref=app
+ 8
For string + is contation?
+ 7
visph great thanks
+ 6
visph very very thanks for your help
+ 1
EVALuate a javascript string...
+ 1
a = "1"
b = "2*2"
alert (eval(a))
// == eval("1") == 1
alert (eval(b))
// == eval("2*2") == 4
alert (eval (a+b))
// == eval("1"+"2*2") == eval("12*2") == 24
alert (eval(b+a))
// == eval("2*2"+"1") == eval("2*21") == 42
+ 1
everything added to a string should result in a string ;)
if you want to evaluate (a)+(b) as a number sum, you could do:
eval(a)+eval(b)
if a and b result to a number, obviously...
[edit] Friend 4 Goodmen
eval("a+b") // not working, as return string concatenation ^^
0
yes