What do you think the output of this function will be?

var mindBoggler = function() {  
  for(var i = 0; i <= 3; i++){
    setTimeout(function(){
      console.log(i);
    }, 1000);
  }
};

mindBoggler();  

You're probably thinking

(1 second)
0  
(1 second)
1  
(1 second)
2  
(1 second)
3  

But the actual output is

(1 second)
4  
4  
4  
4  

How would we fix this to get our desired output?