THE WORLD'S LARGEST WEB DEVELOPER SITE

JavaScript eval() Function

❮ JavaScript Global Functions

Example

Evaluate/Execute JavaScript code/expressions:

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;
Try it Yourself »

Definition and Usage

The eval() function evaluates or executes an argument.

If the argument is an expression, eval() evaluates the expression. If the argument is one or more JavaScript statements, eval() executes the statements.


Browser Support

Function
eval() Yes Yes Yes Yes Yes

Syntax

eval(string)

Parameter Values

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

Technical Details

JavaScript Version: ECMAScript 1

❮ JavaScript Global Functions