It is a language that works of the side of the client, that is to say who executes himself in the navigator and not in the servant.
Its main assignment in adding interactivity to the webpages, that is to say that following the actions (events) of the user the own Web reacts of a way or another one.
As it works
In own document HTML
She can have all the blocks of code that are needed, and following where they are placed executed themselves sooner or later, reason why much people prefer to just put them before closing the label body.
In a different file with extension js
It is the recommendable way but, mainly if scripts is going to have impact in all the pages of the Web, for example if she affects to the menu, since in all the pages we see the menu would be a case in which she would affect to all.
Like in the case previous the call to this external document can be done in any place, although he is recommendable to do it in the final part of head or right before the closing of the body, and it becomes of the following way: