JavaScript Library vs. JavaScript Framework
This is the first lesson of the course “Front-end web development”. You must have already learnt about JavaScript in course “Web design for beginners”. If you cannot remember what is JavaScript, it is a good time that you brush up your knowledge.
Software developers often use the words library and framework. Both contain reusable codes that someone else has written, tested, and proven to be used.
Let’s try to understand what these libraries and frameworks are.
What is a library?
A library is a prewritten set of codes that can be reused. Libraries give useful functions, methods, or objects. You can use them in your application code. Whenever necessary you don't need to rewrite the codes from scratch. You can just use the library to get used to the method.
Eg: There’s a method ‘findInverse(String)’ in a particular library. It will return the inverse of the word that we give. We can straightway call this method in the library whenever we need an inverse of a particular word. We do not need to write the whole logic behind this method everywhere we need that functionality.
Now let us see what a JavaScript library is.
JavaScript libraries
JavaScript libraries are written in JavaScript. There are dozens of JavaScript libraries available. Normally these libraries are focusing on some narrow scope.
Let’s have a look at specific functions where JavaScript libraries are been used.
What are JavaScript libraries used for?
JavaScript libraries serve different purposes. Some of them are listed here with examples.
- DOM Manipulation – jQuery, Umbrella JS
- Data Handling – D3
- Data Visualization in Maps and Charts – Chart.js , ApexCharts
- Animations – Anime.js
- Image Effects – ImageFX
- User Interfaces and Components – ReactJS, Glimmer.js
A framework is a structured platform to develop software applications. It provides a template to plug the necessary codes segments and modify them as necessary. When you are using a framework, you don't need to write everything from scratch. Therefore, it saves time and reduces the risk of introducing new errors. Other than those, there are so many advantages that we can gain by using a framework. They are,
- Avoid duplicate code.
- More secure code.
- Clean and easily adaptable code.
- Can be extended.
There are different types of frameworks such as front-end web frameworks, back-end frameworks, mobile frameworks, etc. These are written in different languages. Let us have a look at the frameworks written in JavaScript.
JavaScript frameworks
There are so many frameworks that have been written using JavaScript. We will have a look at some of them.
- Angular – Angular is one of the most popular, free and open source web application framework which is developed by Google.
- Express – Express is a back-end framework for Node.js which is written in JavaScript. It is free and open-source.
- Vue.js – Vue.js is one of the best JavaScript frameworks to develop cross-platform apps and websites.
- Ember.js – Ember.js is another commonly used JavaScript framework that helps create scalable Single Page Applications.
Difference between library and framework
The technical difference between a library and a framework lies with the programming principle which is known as ‘Inversion of Control’ (IoC). When you use a library, you can use it anywhere you need in the application. You have control of when and where to use it. So, you are in charge of the flow. But in frameworks, it provides some places for you to plug your code or the high-level implementations. The framework will call your code as needed. When you use a framework, the framework is in charge of the flow.