Code executes on the main scope from top to bottom. If you have several functions in the bottom that are being defined but not called and then code in the main scope below them, it would run the code.
So normally (without those async or defer attributes), scripts get excuted in the order in which they are specified in the source code. But if the script tags are in the <head> , the browser will first wait for all scripts to load before it starts executing anything.
Is it compulsory to declare function before its calling?
In C99 every function that you call must be declared before point of the call. However, it is still not necessary to declare it with a prototype specifically. A non-prototype declaration will work as well.
How does a function execute?
A statement that executes a function. It consists of the name of the function followed by a list of arguments enclosed in parentheses. Using the output from one function call as the input to another. A statement that creates a new function, specifying its name, parameters, and the statements it executes.
Directly into the head of the page. Directly into the body of the page. From an event handler/listener.