Why output is 24? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
7th May 2019, 3:53 PM
Sławek J.
7 Answers
+ 6
a+b => "12*2" evaluating gives 24
8th May 2019, 6:36 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 6
I'm surprised it is not 42 which is the answer to everything. JK.
9th May 2019, 6:45 AM
Sonic
Sonic - avatar
+ 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
8th May 2019, 8:49 PM
Heriberto Domínguez
Heriberto Domínguez - avatar
+ 3
To get a+b=5, btw, do: console.log(eval(a)+eval(b)); //or console.log(eval(a+"+"+b));
9th May 2019, 7:35 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
"1" + "2" * "2" = '12' * '2' = 24
8th May 2019, 8:26 AM
Sorry..
+ 2
you need to add parenthesis to 2 * 2 because it is a variable
8th May 2019, 12:13 PM
Preston Dunn
Preston Dunn - avatar
+ 1
"1"+"2*2" = "12*2" = 24
10th May 2019, 9:50 AM
mendel
mendel - avatar