X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript eval() Function

Function Reference 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;

The result of res will be:

200
4
27

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

Internet Explorer Firefox Opera Google Chrome Safari

The eval() function is supported in all major browsers.


Syntax

eval(string)

Parameter Values

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


Function Reference JavaScript Global Functions

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook