If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

What's a JS library?

There are a billion webpages, and many of them are interactive in some way - in fact, many of them are interactive in the same ways. How many websites have you seen that use a slideshow? I've seen hundreds, myself!
For example, here's one from National Geographic:
Screenshot of a slideshow from National Geographic
Here's one from Instagram:
Photo of a slideshow of waterfall photos on Instagram
One more, from The Onion:
Screenshot of a slideshow from The Onion
Now, it's possible that every one of those web developers wrote their own JavaScript code to make a slideshow, but a lot of them probably re-used the same code. As programmers, we should re-use existing code when we can, so that we don't waste our time writing code that another programmer has already written.
In JavaScript, the way we do that is by using a library. A library is a JavaScript file that contains a bunch of functions, and those functions accomplish some useful task for your webpage.
How do we know what functions we can use? We could look at the JavaScript file, if it's short, or better, we could look at the documentation. Most libraries have documentation with a list of available functions or a real-world example.
For example, here's a snippet of the documentation for Galleria, a popular JS library for making slideshows:
Screenshot of the documentation for Galleria
When a programmer creates a JS library and puts it out into the world, they're purposefully deciding to share it with the world - so that often means they put in the effort to come up with great documentation and examples. Perhaps one day you will decide to create a library of some functionality that you find really useful and share it with the world.
But first, how do you actually use a library? I'll show you that next!

Want to join the conversation?