The eval function in JavaScript evaluates the expression passed as an argument and executes it if there is an operation.
The syntax is as follows: eval(string).
JavaScript eval examples
Here is a series of demonstrative examples on the use of eval.
console.log(eval('2 + 13'));
var x = 10;
var y = 3;
console.log(eval('x + y'));
console.log(eval(' x / y'));
However, remember that this function is slower than the alternatives.
It can also be dangerous as it runs the code with page administrator privileges.
Some useful links
Introduction to JavaScript language
Learn JavaScript – basic concepts
JavaScript functions and return
Array method and callback function