JavaScript eval() function

Definition and usage

eval() Function calculates or executes the parameter.

If the parameter is an expression, then eval() Calculate the expression. If the parameter is one or more JavaScript statements, then eval() Execute these statements.

Example

Evaluate/execute JavaScript code/expression:

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

Syntax

eval(string)

Parameter value

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

Technical Details

JavaScript Version: ECMAScript 1

Browser Support

Function Chrome Edge Firefox Safari Opera
eval() Support Support Support Support Support