Global eval() Function - Javascript Global

Javascript examples for Global:eval

Description

The eval() function evaluates or executes an argument.

Parameter Values

Parameter Description
stringA JavaScript expression, variable, statement, or sequence of statements

The following code shows how to Evaluate/Execute JavaScript code/expressions:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from w w w. j  av  a  2 s  . c om
    var x = 10;
    var y = 20;
    var a = eval("x * y") + "<br>";
    var b = eval("2 + 2") + "<br>";
    var c = eval("x + 17") + "<br>";

    var res = a + b + c;
    document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>

Related Tutorials