$(document).ready accepts a callback. A callback is a javascript function. Javascript functions can be passed around just like variables. In the case above you are using an inline anonymous function, that is a function with no name.
You could rewrite your example like this:
function doStuff() {
alert("The page has loaded.");
alert("2nd alert.");
}
$(document).ready(doStuff);
You need to use a function because you cannot pass statements as parameters to a function but you can pass a function.
Note if you don't want to have to type as much there is a shorthand notation that is functionally equivalent:
$(function() {
alert("The page has loaded.");
alert("2nd alert.");
});
or without the inline function:
function doStuff() {
alert("The page has loaded.");
alert("2nd alert.");
}
$(doStuff);