What is the difference between a framework and a library in JavaScript?
Control flow
With a library, you are in charge. You import it and call its functions when needed. For example, Lodash provides utility functions you invoke. With a framework, the framework controls the flow. You write code that fits into its structure, and it calls your code at the right time. Angular and Vue are frameworks; React is often called a library because it focuses on the view layer, though it's sometimes considered a framework due to its ecosystem.
This inversion of control means frameworks often require you to follow specific patterns (e.g., components, services, modules), while libraries are more flexible and can be mixed and matched.
Examples and implications
jQuery is a classic library: you call methods to manipulate the DOM. Angular is a framework: you define components and services, and Angular bootstraps and runs them. React sits in between: it provides a core library for building UIs, but you often add libraries for routing, state management, etc., making it more library-like.
The distinction affects how you architect your app. Frameworks provide more out-of-the-box but can be harder to swap out. Libraries give you more freedom but require more decisions.
- Library: you call the code (e.g., Lodash, Axios)
- Framework: the code calls you (e.g., Angular, Vue)
- React: often called a library, but ecosystem makes it framework-like
- Inversion of control is the key differentiator
Common mistakes
- Thinking React is strictly a library or a framework—it's debated and depends on definition.
- Assuming frameworks are always better for large apps; libraries can scale too with good architecture.
- Believing you can't use libraries inside a framework—you often can and do.

Related questions
- How do I choose between React, Vue, and Angular for a new project?
- Is React still the best choice for building a large web app?
- Should I learn React or Vue first as a beginner?
- Why does my React component re-render too often?
- Can I use React and Vue together in the same project?
- Should I use Svelte instead of React for a new project?