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

JavaScript tutorial

Banner Pubblicitario

JavaScript Calculator

Object in JavaScript

For in loop

Caesar cipher decoder

Slot Machine in JavaScript

Introduction to JavaScript language

Learn JavaScript – basic concepts

Banner pubblicitario

JavaScript functions and return

JavaScript Callback

Callbacks

Array method and callback function

Callback functions – examples