Javascript - Global eval() Function

The eval() function evaluates or executes an argument.

Description

The eval() function evaluates or executes an argument.

Syntax

eval(string)

Parameter Values

Parameter Require Description
stringRequired A JavaScript expression, variable, statement, or sequence of statements

Example

Evaluate/Execute JavaScript code/expressions:

Demo

var x = 10;
var y = 20;/* w ww  . j av  a  2 s  .c  om*/
var a = eval("x * y") + "\n";
var b = eval("2 + 2") + "\n";
var c = eval("x + 17") + "\n";

var res = a + b + c;
console.log(res);

Result