every script tag the page find, it will execute it.
so the first script, it runs myFunction(), but it's not there, ERROR.
For the second, myFunction is there, so OK.
But pay attention that the following is also error:
<script>
myFunction(); // error
var myFunction = function() {
alert("ok");
}
</script>
when you define myFunction with var, it's now a local variable(here its global scope, so global variable), named myFunction, and only assigned to a function during run-time. So during run-time, you call myFunction() but it is not assigned with a value yet, event don't know whether myFunction is a function or not.
when you do it as following
<script>
myFunction(); // OK
function myFunction() {
alert("ok");
}
</script>
A function named myFunction will be created during something like pre-process, which does some initial work.
and after that is the run-time, which handles myFunction(). So now, when it's called, there is a function with the name of it, no problems.