You can store JS files in the _layouts folder, but storing them in the Style Library gives you workflow/change history for free.
If you keep your JS files in the Style Library you can reference them in your MasterPage using the ~sitecollection token by using the
tag, like so: