Organizational Research By

Surprising Reserch Topic

javascript function declaration and evaluation order


javascript function declaration and evaluation order  using -'javascript,function-declaration'

Why does the first one of these examples not work, but all the other ones do?

// 1 - does not work
(function() {
setTimeout(someFunction1, 10);
var someFunction1 = function() { alert('here1'); };
})();

// 2
(function() {
setTimeout(someFunction2, 10);
function someFunction2() { alert('here2'); }
})();

// 3
(function() {
setTimeout(function() { someFunction3(); }, 10);
var someFunction3 = function() { alert('here3'); };
})();

// 4
(function() {
setTimeout(function() { someFunction4(); }, 10);
function someFunction4() { alert('here4'); }
})();

    
asked Sep 15, 2015 by Jef2901
0 votes
4 views



Related Hot Questions



Government Jobs Opening


...