+ 2

alert(5/8+"hi") & console. log(25*87) evaluate the sum and sends to the console/prompt. Why use alert(eval(5/8+"hi))?

Does Alert() have eval() built in?

3rd Jun 2019, 6:13 PM
Arcayno
Arcayno - avatar
5 Respuestas
+ 2
Not really. With eval, "5*5" and 5*5 will both be 25 With alert, only 5*5 will be 25, and "5*5", well, stays "5*5" Eval's point is that it will execute strings, so eval("alert('x')") will execute, and x will be alerted
3rd Jun 2019, 6:16 PM
Airree
Airree - avatar
+ 2
Am I missing the point of eval then? lol typical https://code.sololearn.com/WP0UvZRw4o41/?ref=app
3rd Jun 2019, 6:31 PM
Arcayno
Arcayno - avatar
+ 1
https://code.sololearn.com/W8PjLKojM7xT/?ref=app
3rd Jun 2019, 6:39 PM
Airree
Airree - avatar
+ 1
eval is for strings like inputs then. Got it. Thanks for the clarification Aimee.
3rd Jun 2019, 7:47 PM
Arcayno
Arcayno - avatar
+ 1
Yes, so if you want to, I don't know, make a graph displayer (winkyface) (winkyface), that is extremely useful, so you can get the function very easily, so you can get an input like "18 * x ** 2 + 9 * x + 5 * sin(x)", you can easily use eval
3rd Jun 2019, 7:51 PM
Airree
Airree - avatar