Adding script to DOM not means that script is loaded, the same thing is with any resource, adding image to DOM does not means image is loaded. Loading scripts or images or any url content is asynchronous, DOM not waits for complete of load. Your code is calling function
immediately after adding script to page structure, so script is not loaded yet.
Pure Js solution:
Dynamically load external javascript file, and wait for it to load - without using JQuery
Jquery solution
In Jquery exists helpful method getScript:
$.getScript( "myfile.js", function( data, textStatus, jqxhr ) {
//here script is loaded and functions can be called
});
Last thing to know is that appendChild add child as last child. So taking Your example:
<head>
<!-- other head elements -->
<script src="example.js"></script>
<!-- other head elements -->
<!-- HERE WILL BE ADDED FILE, AS LAST CHILD -->
<script src="myFile.js"></script>
</head>
So myFile.js will be added as last in head and for sure will be not available in scripts added before it.