Animations
API
Arrays
Async
Basics
Challenges
Classes
Console
Dates
Debugging
DOM Elements
DOM Methods
DOM Properties
Event Listeners
Flow Control
Forms
Functions
Global Functions
JSON
Keywords
Libraries (3rd party)
Math
Modules
Objects
Snippets
String
Types
Widgets
Window Object
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.
function EvalTest()
{
// test 1
let x = 10;
let y = 20;
let a = eval("x * y") + "<br>"; //200
let b = eval("2 + 2") + "<br>"; // 4
let c = eval("x + 17") + "<br>"; //27
let output = a + b + c; // output was html of all three lines
document.getElementById("DemoContainer").innerHTML = output;
// test 2
//let x = 10;
//let y = 20;
//let a = eval(x * y * y) + "<br>";
//let output = a; // 4000
//document.getElementById("DemoContainer").innerHTML = output;
}