Global code is JavaScript placed outside every function. In a browser, the engine executes it automatically, line by line, as encountered; function code runs only when called. During page-building, encountering a script pauses HTML parsing and DOM construction while its JavaScript executes. section 2.2.2 section 2.2
Listing 2.2. Global and function JavaScript code
<script>
function addMessage(element, message){
var messageElement = document.createElement("li"); #A
messageElement.textContent = message; #A
element.appendChild(messageElement); #A
}
var first = document.getElementById("first"); #B
addMessage(first, "Page loading"); #B
</script>
The function definition and call sit in global code; the function body runs when called. section 2.2.2
