The format of the script element is very simple:
Web browsers normally load and execute scripts as they are loaded. A web page always gets read by the browser from the top down, just as you would read a page of text. Sometimes you’ll want to wait until the browser is done loading the contents of the web page before the script runs.
Above, this was accomplished by using the onload event attribute in the body element. Another common way to delay execution is to simply place the code to be executed at the end of the code.
Single page apps, which (as the name implies) contain only a single HTML page, are also great candidates for the use of this type of embedding because there will only ever be one place to update the script.