var i = 0; function test(){ function count(x){ return ++x; } alert(i); i = count(i); window.setTimeout(test,3000) } test();