This is an example to explain the variations of load events.
1. onload event
In this case, the message is logged once all the contents of the page including the images and stylesheets(if any) are completely loaded.
2. DOMContentLoaded event
In the above code, the message is logged only after the DOM/document is loaded
3. Self-invoking anonymous function
Here, the message gets logged as soon as the browser interprets the anonymous function. It means, this function can get executed even before the DOM is loaded.