To 'pile on' to pritaeas' answer, using exernal JS files is the way to go.
You will find that having the JS script separate from the HTML of the web page will have your Web page development/debugging/changing code life eased.
For changes to the JS, you can concentrate on the JS. If changing the HTML, you can concentrate on the HTML. For a web site with more than a 'few' pages, the mixing of the JS with the HTML can start to look like a 'jungle' of code.
The more you can separate the 'layers' of your pages, the better.