Your first code snippet: is a Module Pattern Or Immediately Invoked Function Expression(IIFE)
(function()//doing this { them.innerHTML = "Weird<br>"; })();
This when encountered by the Javascript compiler will immediately invoke the function when it encounters
();
and keeps the variables and functions within its scope.You must read Java-script Design Patterns to better understand its use and benefits.
Second code snippet: is just a JavaScript statement.
me.innerHTML = "Not so weird<br>";//and doing this
This when encountered by the JavaScript compiler will immediately execute it.
Remember both snippets executions depends on where its placed.
- So, to answer your other question.
window.onload
is an event fired when the HTML DOM is fully loaded and browser can read all its elements.