First of all. Javascript should be written as js-files and then added with script-tags. It will make your html cleaner and save bandwidth.
But generally it doesn't matter where you put it. Just wrap it in a script tag anywhere in the page.
Make sure you don't use variables which are not declared yet. for example if you add a bunch of javascript at the bottom of your masterpage, you can't access those functions/variables before these scripts are loaded.
It's a good idea to wrap your javascript with $(document)ready(). Then it will not be executed before page is finished loading.
$(document).ready(function() {
});