Why this code doesn\'t work
function callback(num, func) {
for(var i = 0; i < num; i++) {
func();
}
}
callback(4, console.log(\"Hello
That's because when you mentioned console.log(), you asked the js engine to evaluate it and it does and passes the result as the 2nd arg to the callback function and not a function object as it expects and hence the call doesn't behave as u desire. The working case correctly passes a function object when u pass a function(){} construct.