-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy path12.eval.js
More file actions
24 lines (18 loc) · 772 Bytes
/
12.eval.js
File metadata and controls
24 lines (18 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
# Eval - if the argument is an expression then it evaluates expression, else the argument is a statement (can be one or more) then it the executes the statement.
Note: Before running,
1. `eval()` dangerous function, make sure you know what you are doing.
2. Running eval could affect the user's machine with malicious code.
3. `eval()` is slow.
## Reference
1. http://stackoverflow.com/questions/86513/why-is-using-the-javascript-eval-function-a-bad-idea
2. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
*/
// Example
var x = 10;
var y = 20;
// evaluates the expression
eval("x + y"); // 30
// Adding some statements as string
var str = "if (true) console.log('From eval')";
eval(str); // executes the statement