+ 9

Eval into js

Why does eval do it?

9th Feb 2021, 5:20 PM
Friend 4 Goodmen
Friend 4 Goodmen - avatar
8 ответов
+ 8
Пoчему eval так ведет себя в js? https://code.sololearn.com/Wj8d1SU8TPX9/?ref=app
9th Feb 2021, 5:21 PM
Friend 4 Goodmen
Friend 4 Goodmen - avatar
+ 8
For string + is contation?
9th Feb 2021, 5:29 PM
Friend 4 Goodmen
Friend 4 Goodmen - avatar
+ 7
visph great thanks
9th Feb 2021, 5:30 PM
Friend 4 Goodmen
Friend 4 Goodmen - avatar
+ 6
visph very very thanks for your help
9th Feb 2021, 9:43 PM
Friend 4 Goodmen
Friend 4 Goodmen - avatar
+ 1
EVALuate a javascript string...
9th Feb 2021, 5:21 PM
visph
visph - avatar
+ 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
9th Feb 2021, 5:26 PM
visph
visph - avatar
+ 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 ^^
9th Feb 2021, 5:35 PM
visph
visph - avatar
0
yes
9th Feb 2021, 5:30 PM
visph
visph - avatar