Your javascript is going to be executed in the order it is loaded, other than hoisting, where functions can be used before they are written if you use the right syntax.
File 1:
function foo() {
alert("I'm foo!");
}
File 2:
foo(); //alerts "I'm Foo!"
Basically, having two files like
Is the same as combining them and just including them together. If it works like that, it will work seperately as well, other than hoisting.
This is how hoisting works: (this must be in the same file and in the same scope)
foo(); //alerts "I'm foo!" even though we haven't told it to yet.
function foo() {
alert("I'm foo!");
}
This works because functions defined that way will be "hoisted" to the beginning of the execution in that scope.
What WON'T work:
foo(); //undefined!!
var foo = function() { //doesn't get hoisted!
alert("I'm foo!");
}
If you want hoisting, use the other syntax!
One thing you might be wondering is this, but I can't really figure out your question (confusing wording, lol)
What if file 1 has a function that uses a function from file 2?
In that case, you won't be able to use the function in file 1, because the function from file 2 will be undefined at the time file 1 is executed, but you CAN use the file 1 function in file 2 (even at the beginning if you have it hoisted).
Like this:
File 1:
function foo() {
bar();
}
foo(); //bar is undefined! error!
File 2:
foo(); //works!! bar is hoisted and therefore defined already for "foo" to use
function bar() {
alert('from file 2!');
}