eval function

The eval function executes a code line as JavaScript code.

Syntax

javascripteval(a line with code);

Example

In this example, alert with some message will be called:

javascripteval("alert('Hello word')");

Example

In this example, the result of the sum of two variables will be displayed:

javascriptlet code = "let a=10; let b=20; document.write(a+b)";
eval(code);