The Key Difference between a Framework and a Library in Javascript

 Developers often use the terms 'Library' and a 'Framework' interchangeably. But there is a significant difference between them. Today, we are going to discuss that difference.



Both libraries and frameworks are reusable codes written by the programmer. Their purpose is to reduce our burden and help us to write some clean and neat code. 

Let's take an example. Consider a house as a language that you are going to choose. Here it's Javascript.

A House is already been built but we need some furniture and other stuff to make our house look great. This is where the library comes into the picture. You have many options to choose furniture from, like Amazon, Ikea, and etc. This furniture resembles our library to a language here.

But, unlike a library, a framework is like building our own model home or making certain specific changes for the existing design to look better. But, coming to the framework we have very limited options to choose from when it comes to design and other stuff. At last, your contractor or the manager will come into the place to finish the work. 

The Technical DIfference between them lies in a term called Inversion of Control.

When you use a library, you need to call the library and you are in charge of your whole code and the flow of the application. And you need to choose the specific library to use in certain situations. On the other hand, our framework will look after our code and it is in charge of the whole flow of the application. It allows us to fork and plug in the code as needed.

The inversion of control requires a concession of application-design freedom. And frameworks are more opinionated. For example, I would personally consider Vue.js is a highly appointed framework than Angular. It's just one's opinion that what to choose.  

Examples of the libraries in Javascript are jQuery, Parsley, jQuery UI, Ember js, etc.

Examples of the Framework in Javascript are Backbone.js, Vue.js, Angular.js, Meteor.js, etc.

In Summary: 

  • Frameworks and libraries are both codes written by the developer to reuse the code. These help us to perform complex tasks more efficiently.

  • A framework inverts the control of the program. It tells the developer what they need to do and where they need to shoot the code. But on the other hand, the library doesn't. The programmer calls the library where and when they need it

  • The degree of freedom a library or framework gives the developer will dictate how it is opinionated. 


Comments