+ 1
js eval gives some nasty output
I have recently began playing js challenges, and I've come across this code: var a = "1"; var b = "2*2"; console.log(eval(a+b)); The output of this code is 24, but I don't understand how it came to this output. By my logic, it would be like this: eval first evaluates the variable a which is a string and returns 1; then it evaluates b which is a string also, and returns 4; now, concatenating those strings, I think the result should be 14. Am I missing something here?
3 Antworten
+ 5
a+b is evaluated first, string concatenation occurs and the string becomes "12*2"
https://code.sololearn.com/WsRqTWz3hOs7/?ref=app
+ 1
Thank you for clarifying it for me, Gordon!
0
Welcome. Keep up 💪