For the sake of our discussion, let's pretend you've just created a fabulous code that writes out today's date:
Using the above code, lets create a library out of it, so multiple pages can all display a nice date without having to physically include the above code on that page.
Step 1: Open up your text editor (such as notepad), type out the above code, and save it as an individual file with the extension .js (ie: displaydate.js). An external library should include the entire script, minus the surrounding script tags.
Step 2: On all pages that use the above library, create a reference to it by using the below code. It consist of a <script> tag with the optional src property included inside:
By including the above reference, your browser will now download the code stored inside displaydate.js, and run it as if the code was physically typed onto the page. The library file does not have to be stored in the same directory as the page using it. In fact, you can even reference a library that's on a distant domain!
<script src="http://www.yahoo.com/displaydate.js"> </script>