Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
What is the use of JavaScript eval function?
The JavaScript eval() is used to execute an argument. The code gets execute slower when the eval() method is used. It also has security implementations since it has a different scope of execution. In addition, use it to evaluate a string as a JavaScript expression.
The eval() method is not suggested to use in JavaScript since it executes slower and improper usage opens your website to injection attacks.
Example
Here’s how you can implement eval() function
<html>
<body>
<script>
var a = 30;
var b = 12;
var res1 = eval("a * b") + "<br>";
var res2 = eval("5 + 10") + "<br>";
document.write(res1);
document.write(res2);
</script>
</body>
</html> Advertisements
