English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript eval() function

 JavaScript Global Properties/Function

eval()The function calculates or executes JavaScript code represented as a string.

If the string represents an expression, eval() will evaluate the expression.

If the parameter represents one or more JavaScript statements, the eval() function will execute these statements.

If the parameter of eval() is not a string, the parameter returned by eval() remains unchanged.

Syntax:

eval(string)
var x = 20;
var y = 10;
var a = eval('x * y');
var b = eval('2 + 2');
var c = eval('x + 15');
var res = a + '<br>' + b  + '<br>' + c;
Test and See‹/›

Browser Compatibility

All browsers fully support the eval() function:

Function
eval()IsIsIsIsIs

Parameter Value

ParameterDescription
stringA string representing a JavaScript expression, statement, or sequence of statements.

Technical Details

Return Value:The completion value of the given code. If the completion value is empty, it returns undefined.
JavaScript Version:ECMAScript 1

 JavaScript Global Properties/Function