We use these terms almost everyday as developers. These are my notes regarding both with examples and differences.
A framework and a library both contain reusable functions.
You can write a library with reusable functions too that can be used by other developers. There are tons of custom CSS, JavaScript and other libraries available on GitHub. Most of them are shared by other developers as an open source project and anyone can contribute in it, others are private and can be purchased.
Library
A library is basically a set of functions that adds more functionality to your project.
When you need to perform some task, you can call one of those functions. In many cases, the functions are made for an instance of a particular class so you need to create the instance first and then call the function.
Your project is ready but you can add or remove libraries based on your need. It’s like your house or car. It’s already built but if you want to make it look nicer or add some additional “features”, you can go to some stores and get stuff to add. You don’t need to create a new car just to decorate it!
Examples: React, jQuery, Three.js, Lodash
Framework
A framework is different in that sense. It’s like a skeleton.
It’s like you have a set of features or functionalities in your mind and you need to decide from the beginning which “tool” aka framework to use to accomplish that.
Kinda like making a car or house from scratch! Yes, like making Ferrari or similar cars from scratch. Once you go with a Ferrari, you can not have some features from Tesla. For that, you need to swap the Ferrari for Tesla.
A framework has more functionalities built in. Some of those functionalities / features / functions gets fired on a specific behaviour of users or the app, other times, you need to add some kind of specific behaviour in order to fire those functions.
Examples: Angular, Vue, Django, Express
You might have got the idea regarding the technical difference. It’s about the control.
When you use a library, you have much more control over it but when you use a framework, you lose most of that control.
It’s all about what level of freedom you want as a developer.
basics definition differences framework library