+ 13
Why output is 24?
8 ответов
+ 6
a+b => "12*2"
evaluating gives 24
+ 6
I'm surprised it is not 42 which is the answer to everything. JK.
+ 5
Swap to Spanish
because both are string and are concatenated, this is what it does (a + b), and then they are multiplied as values when using eval ()
a = "1"
b = "2 * 2"
eval (a + b) = eval ("1" + "2 * 2") = eval ("12 * 2") = 24
+ 3
To get a+b=5, btw, do:
console.log(eval(a)+eval(b));
//or
console.log(eval(a+"+"+b));
+ 2
"1" + "2" * "2" = '12' * '2' = 24
+ 2
you need to add parenthesis to 2 * 2 because it is a variable
+ 1
"1"+"2*2" = "12*2" = 24