-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval.js
More file actions
19 lines (14 loc) · 782 Bytes
/
Copy patheval.js
File metadata and controls
19 lines (14 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//functionalities of eval functioon and why not to use it...
// in case the argument is a string returns string
console.log(eval('2 + 2'));
// expected output: 4 as string
console.log(eval(new String('2 + 2')));
// expected output: 2 + 2 but but but it here returns the string object instead of the expected string
// its solution is to first define the string object and then pass it as string in the eval funtion.
const exp = new String('2+2');
console.log(eval(exp.toString()));
// this will just return the expected ans that is 4;
console.log(eval('2 + 2') === eval('4'));
// expected output: true it returns true because we are just comparing equal strings
console.log(eval('2 + 2') === eval(new String('2 + 2')));
// expected output: false because they are different.