I am running following code on Chrome console and getting different execution time.
I create two functions with same body. first one is function declaration and second one is function expression.
var t= new Date().getTime();
function fun1(){
for( i=0; i < 1000000; i ++)
{
a=i;
};
};
fun1();
console.log(new Date().getTime() - t); // nearly 2ms;
t= new Date().getTime();
var fun2 = function (){
for(i=0; i < 1000000; i ++)
{
a=i;
};
};
fun2();
console.log(new Date().getTime() - t); //nearly 900ms
Why is different behavior for same loop?