The DOMContentLoaded event
Running your code when the DOM is ready
Using anonymous functions as event handlers
It's also common to use anonymous functions (functions without a name) when creating the function to handle an event.
This code works exactly the same as the previous example. In this code, instead of passing a function name, we define the function right there. The only difference is the function doesn't have a name. When the DOMContentLoaded event fires, it will run this function.
Anonymous functions are useful when you only need a function once and won't need to call it anywhere else.