Home » Jquery » What is the difference between a JavaScript framework and a library? [duplicate]

What is the difference between a JavaScript framework and a library? [duplicate]

Posted by: admin November 30, 2017 Leave a comment

Questions:

Possible Duplicate:
Framework vs. Toolkit vs. Library

I would like to know what is the difference between a JavaScript framework and a library by using some example.

For instance, jquery, backbone.js and jasmine are JavaScript framework or library? And why?

Can you provide some example of JavaScript framework and a library using the sentence Don't call Us, We'll call You.

Answers:

Even tho this question is highly subjective, my personal opinion about those two is this:

  • Framework: this describes a given structure of “how” you should present your code. Pretty much like a code-template, along some helpers, constructors etc. to solve/simplify a specific problem or bring your architecture in “order”. Examples, “Backbone“, “requireJS“, “socketIO“.

  • Library: Is an entire toolkit which highly abstracts different layers, like browsers / DOM models / etc. Also as a good toolkit, it offers a lot of tools and neat stuff to work with, which in general, simplify your coding experience. Examples “jQuery“, “MooTools“, “YUI

Questions:
Answers:

I agree with jAndy, in my opinion a framework imposes structure upon your code in order to address a particular problem and a library is a generic set of tools that aid you in various tasks, without necessarily addressing the same problem.

In this respect:

  • jQuery is a library because it abstracts a lot of browser incompatibilities but imposes no structure on your code.
  • underscore.js is a library because it’s a collection of utilities to manipulate data structures and other goodies.
  • backbone.js is a framework because it structures your front-end code to match the MVC pattern.
  • Jasmine is a framework because it structures your code so that you can do BDD easily.

Regarding your suggested example, frameworks fit the don't call us paradigm, because most of them impose the flow of the code (some sort of inversion of control). You call the libraries, they don’t call your code.

This is a subjective opinion, so take it as such.

Questions:
Answers:

A framework encapsulates common application functionality, allowing the developer to focus on the parts that are unique to their application. That means the developer writes pieces of code that get called by the framework when various things happen; Ex: backbone.js, or jasmine.
Libraries are packages of code that typically get called by your application to perform a task, like DOM manipulation or HTTP requests. Ex: jQuery.

Questions:
Answers:

A JavaScript library is a library of pre-written JavaScript which allows for easier development of JavaScript-based applications.

and Some JavaScript libraries, such as YUI, are classified as frameworks since they exhibit full-stack capabilities and properties not found in general JavaScript libraries.

Questions:
Answers:

JavaScript is a scripting language.

JQuery is a JavaScript library that handles many commonly used features and also handles the differences between, e.g., Internet Explorer and standards-compliant browsers. It’s something you can use to reduce the amount of work when creating web-based applications.

Questions:
Answers:

There is no real definition of the difference between those two, but in general I would say that a framework is a more general “multi-tool” thing than a library, which is usually very specialized.

For example, Sylvester is a matrix and vector math library. It is very specific in its functionality.

A framework like Prototype on the other hand offers much more than just a limited set of very specialized functionality. It may even use or consist of multiple libraries internally.

Important:
In the end, people use “framework” and “library” as they see fit. Unfortunately 😉