User:The Transhumanist/Workshop boilerplate/The ready event listener-handler

The ready event listener/handler
The ready event listener/handler makes the rest of the script wait until the page (and its DOM) is loaded and ready to be worked on. If the script tries to do its thing before the page is loaded, there won't be anything there for the script to work on (such as with scripts that will have nowhere to place the menu item mw.util.addPortletLink), and the script will fail.

In jQuery, it looks like this:

You can do that in jQuery shorthand, like this:

Or even like this:

The part of the script that is being made to wait goes inside the curly brackets. But you would generally start that on the next line, and put the ending curly bracket, closing parenthesis, and semicolon following that on a line of their own), like this:

This is all explained further at the jQuery page for

For the plain vanilla version see: http://docs.jquery.com/Tutorials:Introducing_$(document).ready