Function code is JavaScript placed inside a function. Unlike global code, which runs as the engine encounters it, function code runs only when something calls it—global code, another function, or the browser. section 2.2.2
During page construction, encountering a script element pauses DOM construction while the browser executes JavaScript. Defining a function does not run its body; a call does. 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 listing contrasts a function definition with global code that calls it to add a message to the page. section 2.2.2
