Execute JavaScript code with eval():
let x = 10;
let y = 20;
let text = "x * y";
let result = eval(text);
Try it Yourself »
Never use eval(). Use code or a function instead:
let x = 10;
let y = 20;
let result = x * y;
Try it Yourself »
The eval()
method 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.
Executing JavaScript from a string is an BIG security risk.
With eval(), malicious code can run inside your application without permission.
With eval(), third-party code can see the scope of your application, which can lead to possible attacks.
eval(
string)
Parameter | Description |
string | A JavaScript expression, variable, statement, or sequence of statements |
eval()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!