PDA

View Full Version : JS vs JQ



Deadweight
10-09-2013, 02:17 PM
I am just wondering if there are things that javascript can do that jquery can not do?
Which one would you suggest is better on a website?

Reason why i am asking this is because i was playing around with jquery on my own and i found it is very easy to use.

jscheuer1
10-09-2013, 02:53 PM
They can do the same things on and for a page, even extending to AJAX server interaction if supported by the host and desired. jQuery is a library built upon javascript. It allows you to do more with less typing. But, if you're willing to type everything out, including creating your own routines for parsing all of the myriad* things that jQuery can parse for you, and for executing the myriad* operations with callbacks and lasting references that jQuery also provides, javascript can do anything jQuery can. jQuery can always do whatever javascript can do because it's allowed to use javascript. I don't think there are any cases where a pure javascript syntax is required for anything complex in jQuery**. But there are times when it might make more sense. You can overdo jQuery to a point where it's slowing things down and/or where you're typing more than you have to.

One thing javascript alone cannot do is load a complex set of existing routines from a third party server that are likely already cached on the user's computer as happens when jQuery is loaded from Google or jQuery.com.


*You really only need to create or have on hand routines for the parts of these things that your script uses. But the more code you have, the more likely you will need more and more of these sorts of things to do what jQuery can do.

**Actually I just thought of something. If you want compatibility with - say IE 5.5 or less, that or parts of that, has/have to sometimes be done in javascript alone.

djr33
10-09-2013, 04:14 PM
Phrasing the question that way implies a misunderstanding of the situation. jQuery is a library written to automate frequent procedures in JavaScript. That's all. At the level of programming theory, I imagine both can do any task, in theory, although not in the same way (or as efficiently), and jQuery might, in some cases, not have permission to do certain UI/output procedures without just resorting to regular JavaScript.

But the real problem is that jQuery is JavaScript. It's a script that adds direct access to frequent procedures, but it's not something else. That's like asking whether the engine or the car is best for going from place A to place B.

Further, regardless of everything else, there's no reason to exclude JavaScript if you're using jQuery. Just use whichever when it's necessary. Certainly there is nothing that only jQuery can do because it is written in JavaScript (and at the very least you could entirely rewrite that functionality yourself without using the prewritten library). And since JS is always available to JQ, I don't see the problem there either.

John's reply touches on some aspects of jQuery that may be problematic (such as compatibility with IE 5.5), but that's only because jQuery isn't designed to deal with all of that; JavaScript isn't either, but to either you could add this manually. So relying entirely on jQuery is a bad idea, but that can be said about anything.

jscheuer1
10-09-2013, 05:10 PM
The compatibility issue is a double edged sword. Sure if you want certain things to work in IE 5.5 you would need a javascript workaround for jQuery. But if you don't use jQuery (version 1 series), you need workarounds for all major browsers for some things, for various IE versions 6 to 10 and beyond on many things.

IE 5.5 and less just aren't used much if at all any longer anyway. So unless you're targeting developing countries or some other demographic where you might find a lot of IE 5.5 (assuming even that those niches exist. Even developing countries are probably up to at least IE 6). Also IE 5.5 will not render well or will not render at all like about 90% of today's web pages. Lack of support for it is no huge loss.

With the advent of jQuery version 2, support for IE is being dropped. Well IE less than 9. From 9 (pretty much) and later (even more so) MS has been making a "real" browser for a change. One that requires no special treatment other than a clear path to the standard methods for doing things. jQuery has always provided that for any browser capable of it.

djr33
10-09-2013, 06:32 PM
Certainly that's true. But it just makes it more clear that attempting to think of "JQ" and "JS" as different things is the wrong way to go. Depending on your situation, both can be useful, and sometimes both are necessary (or at the very least using both is more efficient than using only one).