eval-1

 

eval() is a function which will be used to evaluate expression and argument of the eval() function is a string. In this example we are evaluating 3 example x * y, 2+2 and x+17 which will result in 600,4 and 37.

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <button onclick="evaluateExpression()">Evaluate expression</button> <p id="sample"></p> <script> function evaluateExpression() { var x = 20; var y = 30; var a = eval("x * y") + "<br>"; var b = eval("2 + 2") + "<br>"; var c = eval("x + 17") + "<br>"; var d = eval("18 + y") + "<br>"; var result = a + b + c +d; document.getElementById("sample").innerHTML = result; } </script> </body> </html>
Output