I've seen that java-script files are stored separately in js folder. That allows it is easy to organize if you've lot of code to put into. In documentation there is way mentioned how to add into template files or link external.
I hope the documentation link that is given in this post will answer most of your questions. If not, let me know what exactly you're trying for. I'll see with what i can help.