What is the difference between a framework and a library in JavaScript?

Updated October 2026 · How we answer

Short answerA library is a collection of functions you call; a framework calls your code and dictates the structure. Inversion of control is the key difference.

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.
From our shopsCaseMorph: Type an idea, see a custom phone case in seconds, then print a one-of-one.