Tech Insights

JavaScript Framework vs Library: What’s the Difference?

Joana Almeida
- 3 min. to read

At first glance, a programming framework and library may seem to be the same thing, or even similar in concept, but there is a big difference. It all comes down to how they are meant to be used.

These definitions can be applied to any language. But we’ll be specifically focusing on the differences between a JavaScript Library and vs Framework so we can provide more concrete examples.

The Difference Between Library and Framework

While both Frameworks and Libraries are chunks of code written to solve specific problems. Their difference is mainly the control a developer has over its use.

Library Definition

A Library is a package of code that developers can use in their own projects to help solve a specific problem. The objective of a library’s code is to be flexible and highly reusable so it can be deployed in many different kinds of projects. Developers are in control of exactly when to use the library in their own code and can use it more than once if needed.

Framework Definition

A Framework, on the other hand, provides a more tightly structured code in which developers can introduce their own code in specific points of control. These points allow the extension of the framework’s functionality to fit the developer’s specific needs. The framework is the one in control of when to call the code developers have provided when it deems necessary.

The key difference here is the developer’s control over the code’s usage. Frameworks call the developer’s code, which in turn can use Libraries in order to solve common and/or complex problems more easily.

As a real-life analog, let’s imagine the production of bread. Producing bread has several processes that need to happen in a specific order. A framework for producing bread could be, for example:

// Make Bread Framework
function plantWheat() {
    // Your code for Planting Wheat goes here
}

function millFlour() {
    // Your code for Milling Flour goes here
}

function makeBread() {
    // Your code for Making Bread goes here
}

function produceBread() {
    plantWheat();
    millFlour();
    makeBread();
}

Whatever happens, makeBread() will always run in the same way. First, it’ll plant wheat, then mill it for flour, then use that flour to make the break.

However, this framework gives you the points of control plantWheat(), millFlour() and makeBread() so you can specify the way in which wheat is planted, flour is milled, and bread is made. Depending on the internal workings of these control points, the type of bread you produce can be radically different, even though the framework for producing them stays the same.

Let’s define this process a little more by developing these control points.

We want wheat to mill for flour, to then use to make bread. But each of these steps can use wildly different ways to produce what we need. So, how do we go about this? This is where Libraries come in.

import * as farm from './modules/farm.js';
import * as windmill from './modules/windmill.js';
import * as bakery from './modules/bakery.js';

// Make Bread Framework
function plantWheat() {
    farm.plantWheat();
}

function millFlour() {
    getWheat();
    mill.millFlour();
}

function makeBread() {
    getFlour();
    bakery.makeBread();
}

function produceBread() {
    plantWheat();
    millFlour();
    makeBread();
}

Here we’re using three libraries to abstract the wheat planting, the milling of flour, and the making of bread. We’re delegating those responsibilities to a “farm” library, a “windmill” library, and a “bakery” library, respectively. Their inner workings are unknown to us. But we know that they will produce what we need by the end of their respective processes.

Now imagine that we don’t have access to any windmills in the area. But instead, there is a watermill nearby that can mill flour for us. Our code can change to something like:

import * as farm from './modules/farm.js';
import * as watermill from './modules/watermill.js';
import * as bakery from './modules/bakery.js';

// Make Bread Framework
function plantWheat() {
    farm.plantWheat();
}

function millFlour() {
    getWheat();
    watermill.millFlour();
}

function makeBread() {
    getFlour();
    bakery.makeBread();
}

function produceBread() {
    plantWheat();
    millFlour();
    makeBread();
}

By using a different library, we were still able to achieve the same result with minimal changes. However, note that even while we used different libraries to achieve our purposes of producing bread, the framework for production has not changed.

What is JavaScript?

JavaScript is a programming language and a core technology of the World Wide Web as we know today. It is used almost universally when creating web pages alongside HTML and CSS, which led to it becoming inherently present in all internet browsers. Besides that, JavaScript also sees use as a scripting language for many offline applications.

JavaScript Libraries

Here are some examples of Libraries used in JavaScript projects:

  • jQuery: a popular library that features HTML DOM traversal and manipulation, event handling, animation, among other functionality.
  • React: a library that allows you to build interactive user interfaces using components.
  • Angular Material: a library that provides many visual components that follow Google’s Material Design for Angular web applications.
  • Redux: a library that allows your JavaScript applications to easily implement and manage your application’s state. It is often used with other libraries to build an interface on top of its functionality.
  • Three.js: a library used to create and display animated 3D computer graphics on a web browser. Can be used alongside the HTML5 canvas element, SVG or WebGL.
  • Lodash: a library that provides many utility functions for common programming tasks when working with arrays, numbers, objects, strings, and others.

JavaScript Frameworks

Here are some examples of Frameworks used in JavaScript projects:

  • Angular: a framework used to build web, mobile and desktop applications all with one codebase.
  • Ember.js: a framework used to build web applications with rich user interfaces.
  • Vue.js: a framework that at its core primarily deals with building user interfaces and single page applications. Can be extended with several officially maintained libraries and packages.
  • Express: a fast, minimalist framework used to build backends for web applications for Node.js.

Key Differences in JavaScript Framework vs Library

While the difference between a Library and a Framework will stay the same no matter the language you develop in, let’s analyze how that difference translates to JavaScript specifically.

Frameworks in JavaScript will usually provide you with a backbone for building and developing (mostly) web applications and pages, be it frontend or backend.

On the other hand, Libraries will provide you with utilities to enhance your web application, be it visuals, such as tools for animations and reactive content, or programming utilities that reduce and streamline certain tasks by reusing flexible code.

Conclusion

The basic difference between a Javascript library vs framework (or in any other language) is: 

  • Your code will call a Library.
  • A Framework will call your code.

A Framework will usually define the backbone of your application, while the library will help you develop its visuals, internal functions, and algorithms.

If you need to hire remote JavaScript developers or, more specifically, hire ReactJS developers remotely to help develop your next project, DistantJob can help you find the perfect remote candidates that fit your company’s culture and needs.

Subscribe to our newsletter and get exclusive content and bloopers

or Share this post

Are you our next superstar remote developer?

You live, breathe and eat code, and have fun figuring out how to solve problems. And you love living in South America or Eastern Europe. But you don’t feel as fulfilled as your friends in North America.

I NEED A JOB