JavaScript (now standardised as ECMAScript) can be used to script the contents of pages, change their appearance, or control their various on-place widgets.
The implementation of JavaScript varies from browser to browser and sometimes has many bugs. Use with care.
A general rule of the thumb is that your site should not depend on JavaScript.
Do not use JavaScript for linking to another page, changing the appearance of a link on hover, generating HTML, or other things for which plain HTML would do.
Examples for good uses of JavaScript
Form Validation and Automation at the browser's side. (which does not preclude you from having sanity checks at the server).
Games. :-)
Navigation Menus. (again - the site should not depend on them).
More about it
I prepared a discussion of the pros and cons of using JavaScript in pages one writes.