Can jQuery do everything that JavaScript is doing, too?

They can do everything that jQuery can do with JavaScript - jQuery is JavaScript under the hood

Yes,“pure” JavaScript can do everything that jQuery can do and then some. Conversely, jQuery can not do everything that can be done in “pure” JavaScript.

It seems a common misconception that jQuery and JavaScript are different languages.

IMHO it is more correct to think of jQuery is a “tool” that can be used to help write code without needing to “reinvent the wheel”.

Using jQuery is a trade off between not needing to write more lines of often more verbose code and needing to “include” the pre-written code in the library.

In one sense it is a shame that many learn jQuery syntax but never gain an understanding of what or how the code is working, but on the other hand, to be fair, compared to learning how to write code that works cross-browser, jQuery could have a gentler learning curve.

Yes I know, I didn’t mean it like that. I meant features in jQuery that were so popular that they were introduced to modern JavaScript as a short cut. The main example I know of is the query selector.

It used to not be possible to make a selection using CSS rule syntax in vanilla JS without jQuery or your own custom algorithm in the background but now it is.

I know jQuery is just an extension to JavaScript and not a completely separate language.

it’s not even an extension. it’s just a bunch of some very clever JavaScript functions by some very clever people making coding easier.

For what it’s worth, my handful of attempts to do this didn’t go well. A lot of jQuery’s parts are tied together, so it can be difficult to extract a single function without extracting large swaths of the library as a whole.

That’s one of the big disadvantages of jQuery

I don’t blame them in the slightest for taking this approach. They are building a library designed to make writing JS less verbose. Making every function in jQuery self contained would drastically increase the file size and make maintaining the library more difficult.

The vast majority of developers don’t want to cherry pick functions anyway. They just want to install it and have it just work.

If I were one of the builders of jQuery I’d do the exact same thing.

For the most part, jQuery does try to be modular and self-contained. When you look at the jQuery src file you’ll find that it’s nothing more than a series of requests for different features of jQuery.

What’s less known, is that they’re ordered so that the upper items don’t rely on the lower ones, with core, selector, and traversing being the most fundamental parts that don’t use any of the below, whereas ajax, event, and effects are much more likely to use other parts of jQuery.

If you do want to cherry-pick, you can make your own custom jQuery build by picking and choosing the parts of jQuery that you want. The web-interface makes for a quick and easy way to achieve this, that results in decent filesize savings.

Another option if you don’t want to trim down a monolithic library, is to instead use several smaller micro js libraries that you can swap in and out pretty much at will.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.