My documentation skills leave much to be desired, so if there is anything you want clarified, feel free to ask.
The specific instance you mentioned is a closure. Each iteration through the loop, you want to pass the value of i into the function, but by default, javascript uses whatever the value of a variable is at the time a piece of code is executed, not what it was at the time the piece is instantiated. In this case, since the query function sends out an AJAX request, and the callback isn't executed until the request returns (which is likely to happen long after the loop is finished), the value of "i" would be the same for all instances of the callback. To fix this, we use a closure, which locks the value of i in each iteration to the variable x inside the closure, giving each callback a unique value of x. The closure is executed immediately, which is why we have to return the actual callback function inside the closure.
Does that make sense? Google "js closure" to get a better idea of what they do and how to use them (
this is a fairly good explanation).