0
What will be the output of the console.log function and how?
Note: if your answer is 2 can you explain to me how and why not zero logically it should return zero from the array. var funcArray = []; for ( var i = 0; i < 2; i++ ){ funcArray.push( function(){ return i } ) } console.log( funcArray[0]() );
4 Réponses
0
why zero?
Every array element is actually a function which returns the value of I and you see, what's the value of i there after the for loop... it's 2 isn't it! That's why every function will return the same and that is 2 here.
+ 1
console.log() takes almost anything as input and outputs in the console.
To see it in working go to the js section and try writing:
console.log("hello console");
+ 1
i appreciate it bro :)
0
can you do this for me again :)