Skip to content
Akin C edited this page Aug 15, 2017 · 16 revisions

Welcome to the Javascript-function-eval- wiki!

Javascript´s eval function takes a string as an argument. This string can contain Javascript code which will be performed:

eval
(   
    //Outputs "Hello World!"
    'alert("Hello World!")'
);

The example above is a direct call of the function eval and it could bring with its use some disadvantages. One is the ability to change code within the scope of a function which eval is used. For avoiding that, one could use strict mode it seems or wrap eval in a nested function:

function anyFunction(code)
{
   //Nested function
   (function()
    {
        eval
        (   
            'alert(code)'
        );

    })();
}

The second issue is that the performance costs could be high. The solution for that is an indirect call of the eval function:

(0,eval)(code);

STILL IN WORK!

Clone this wiki locally