-1

I'm new to web development, I'm discovering javascript and all its capabilities. I'm currently learning jQuery and it made me wonder: "what really is a library ?".

From some so/internet search I understand that jQuery is a library, although some people also consider it a framework as it help/force you to change the way you code js.

For me, a library is a set of functions and classes to help the programmers on a particular point.

As I understand it jQuery doesn't seem to only add function or classes contrary to other javascript libraries such as math, for example or even other jQuery plugins like datatables etc...

To me, jQuery at its base just looks like another way of presenting js code.

So to summarise my questions are:

  • Is jQuery a "normal" library like Math for c++, python or even js?
  • How does the js engine understand jQuery? (some sort of compilation ?)
  • Can every js engine understand jQuery as long as they have the jQuery.js file, or is there something already embedded inside the engine for jQuery.

I also took a look at this very interesting so post on Is a jQuery compiler possible?, but it just blurred me the line between library and jQuery even more.

Any hint or link to how js/jquery combine would be helpful!

m.nachury
  • 882
  • 5
  • 21

2 Answers2

3

Is jQuery a "normal" library like Math for c++, python or even js?

Yes. It's just a collection of functions, etc.

How does the js engine understand jQuery? (some sort of compilation ?)

jQuery is just code written in JavaScript using the standard features of the browser (the DOM, etc.). (Well, and some non-standard ones it feature-tests for to get around browser idiosyncracies.)

Can every js engine understand jQuery as long as they have the jQuery.js file, or is there something already embedded inside the engine for jQuery.

jQuery is designed for the browser environment, so it won't work correctly in a non-browser environment without additional dependencies (a DOM library, etc.).


For the avoidance of doubt: There's nothing you can do with jQuery that you can't do without jQuery, using JavaScript's standard library, the DOM API, and other browser APIs directly. All jQuery does is provide an alternate API for doing DOM manipulation, provide some utility functions, and define a standard way to add features to extend jQuery with more functionality (e.g., "jQuery plugins").

And for completeness:

  • jQuery is not a language, although it's a common misconception that it is. You don't do something "in jQuery" or "in JavaScript." The correct contrast is "with jQuery" or "with the DOM" (or "without jQuery").
  • There are other libraries which also fill the same sort of "make the DOM easier" niche, although jQuery is by far the most successful of them.
  • There are entirely different approaches to handling browser-based interfaces, provided by a spectrum of projects from libraries (like KnockoutJS and many others) through light(ish) frameworks (like React and others) to full-on frameworks (like AngularJS and many others).
T.J. Crowder
  • 879,024
  • 165
  • 1,615
  • 1,639
  • I guess It's just too different from c++ for me to understand that a js library can add functionality such as `$( "li" ).addClass( "bar" );` as a `function`. I see where I was wrong. Thank you! – m.nachury Aug 30 '17 at 16:59
  • 1
    @m.nachury: I'll bet it's the `$` that's tripping you up. In JavaScript, unlike C++, `$` is a valid identifier, just like `A` or `foo`. jQuery doesn't add any new syntax, it's just JavaScript code. In your example, you're just calling a normal everyday function (which you're referencing as `$`), passing in a string, and then using a method on the object it returns. Other than the `$` thing, you could do the same in C++ by defining a function that returns an object with methods on it. – T.J. Crowder Aug 30 '17 at 17:07
  • Yep, that `$` was tripping me, I thought it was specific to javascript. That changes a lot of stuff... – m.nachury Aug 30 '17 at 17:11
1

Its pretty simple how you understand a library and a framework when it comes to jquery its a library because it dose'nt add any additional jquery approch whatever you see in jquery is present in javascript what jquery does is shorthand your code and help you chain functions which was not that much possible in javascript and when it comes to plugin they all are also part of javascript functions

RAHUL S R
  • 1,529
  • 1
  • 9
  • 20