+ 1
Need explanation for this JavaScript code
var x = "2*2"; var y = 4; var z = eval(x + y); alert(z); Output is 48 but I don't understand why.
5 Respostas
+ 5
1. It declares x with the string expression of "2*2" to indicate multiplication of 2 by 2 without actually solving it.
2. It declares y with the number 4.
3. It declares z. x + y is appending the y value (4) to the x ("2*2") because x is the string, making it a 2*24, and evaluates it, resulting in the answer being 48.
+ 2
Now I understand, thank you ☺
+ 2
EoflaOE Thank you !
+ 1
You are welcome!
0
You are welcome