The methods we have seen throughout the jQuery library often take at least one function as a parameter. For convenience, we often use anonymous functions , so that we can define the function behavior right when it is needed. This means that functions are rarely in the top-level namespace; they are usually inner functions, which means they can quite easily create closures.
Nearly all of the code we write using jQuery ends up getting placed inside a function passed as an argument to
$(document).ready(). We do this to guarantee that the DOM has loaded before the code is run, which is usually a requirement for interesting jQuery code. When a function is created and passed to
.ready(), a reference to ...