The browser reads your html from beginning to end, and can execute it as it is read and parsed into executable chunks (variable declarations, function definitions, etc.) But at any point can only use what's been defined in the html before that point.
This is different from other programming contexts that process (compile) all your source code, link it together with any libraries you need, and construct an executable module, and which point execution begins.
You can define functions that refer to items (variables, other functions, etc.) that are defined further along, but you can't execute those functions until all the pieces are available.
As you become familiar with javascript, you will become intimately aware of your need to write things in the proper sequence.
Revision: To confirm the accepted answer (above), use Firebug to step though the script section of a web page. You'll see it skip from function to function, visiting only the first line, before it actually executes any code.