1

I was reading a thread and saw this post, which says that Javascript is faster than Jquery because it uses native code. But why is the use of native code faster? Is this always the case? What impediments does Jquery have in performance?

closed as unclear what you're asking by gnat, user53019, GrandmasterB, Kilian Foth, user7007 Dec 19 '13 at 14:02

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • What that post actually says is that getElementById is faster, because it uses native code. The jQuery selector will also use getElementById, but it first needs to do a lot of tests and comparisons on the text. You have conflated that to mean that javascript is faster than jQuery, but it doesn't mean that at all. – Robert Harvey Dec 18 '13 at 23:42
15

First of all, we have to get something straight:

Javascript and jQuery are not two completely different things: jQuery is a Javascript library.

jQuery:

jQuery is a cross-platform JavaScript library designed to simplify the client-side scripting of HTML.

Javascript:

JavaScript (JS) is an interpreted computer programming language. As part of web browsers, implementations allow client-side scripts to interact with the user, control the browser, communicate asynchronously, and alter the document content that is displayed.

That said, the common trend among programming languages and libraries is that the library is always going to be slower because it is more code to run alongside your actual program.

For more information, check out this post. It's pretty similar to what you're asking.

1

The link you posted is not that JavaScript is faster per se, but rather that calling the native DOM method is faster than calling a JavaScript abstraction that eventually calls the same DOM method.

For tasks that jQuery does well, such as gathering a list of DOM elements based on a class name, it would be difficult to write a "pure" JavaScript function that does the same task measurably faster. (There are the occasional browser-specific optimization... but jQuery already includes several.)

  • document.getElementsByClassName is a "pure javascript function" which does exactly that without all the overhead. – Sam Sep 8 '17 at 12:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.