BonsaiDen / JavaScript-Garden

A collection of documentation about the most quirky parts of the JavaScript language.
http://bonsaiden.github.com/JavaScript-Garden
MIT License
3.45k stars 559 forks source link

Topic Name : Hidden Use of eval #359

Open divyanshu-rawat opened 7 years ago

divyanshu-rawat commented 7 years ago

setTimeout and setInterval can also take a string as their first parameter.


function foo() {
    // will get called
}

function bar() {
    function foo() {
        // never gets called
    }
    setTimeout('foo()', 1000);
}
bar();

In node v7.3.0 Here setTimeout('foo()', 1000); will throw TypeError: "callback" argument must be a function