Can jQuery do everything that JavaScript is doing, too?

I worked so far with PHP and MySql, but for a while I started to learn jQuery and not JavaScript because someone told me that these days you can do everything with jQuery and you don’t need to learn JS because is too messy. If you want array you have array in jQuery, too, if you want objects you have them, too, told me that guy.
So I ask you, because I’m not sure now, knowing from the old times that JS is the base, can jQuery do any job?

jQuery is just JavaScript.

jQuery isn’t as necessary today as it was years ago but it still has a nice simple API for working with events and DOM updates. Regardless, you’ll need to learn JavaScript as that’s the language that you need to write to use jQuery.

2 Likes

can jQuery do any job?

Once you step outside the boundaries of jQuery’s functionality (e.g. DOM manipulation, AJAX requests etc) then you’ll need to either write the code yourself in vanilla JS, or find a 3rd-party library/component to handle that for you.

I see, I still have to learn those long name methods from JS, comparing with the short ones from jQuery :(. I thought that I will escape only with jQuery :).
I put the question here because I saw a lot of jobs, on freelancer websites, for php, mysql, jquery and not js.

No jQuery can only do a small part of what JavaScript can do.

jQuery is now little more than a wrapper around a few simple JavaScript commands as everything that jQuery provided that was useful now has an equivalent command built directly into JavaScript itself.

In a few more years jQuery will no longer exist - they have already started removing the code to support older browsers that no one uses any more.

Anyway, to properly use jQuery right from when jQuery was first created you need a reasonable understanding of JavaScript first to be able to use it as there are many many things that jQuery cannot do.

1 Like

Felgall, then tell me: what about the problems that JavaScript had on cross browsers? From what I read only jQuery can help you in this case.

jQuery is written in plain JavaScript. It uses one of the possible ways of handling cross browser coding to support antiquated browsers that don’t support the modern JavaScript commands. You can either handle it the same way in plain JavaScript as the JavaScript jQuery uses to do it or any other way of writing code that effectively does the same thing.

jQuery can’t do anything that can’t be done in JavaScript because jQuery is just a collection of JavaScript code.

What jQuery is good at is in helping to reduce the amount of code that has to be written by the developer. As already said, modern web browsers don’t need as much code now, but when dealing with older web browsers, the benefits of using jQuery can be quite nice until you develop your own set of tools.

From what I read so far I agree with you Paul. I know a little js, from college, but not too much. I’m at the sec jQuery book, and is not old book, and the authors say that you write less code with jQuery, the same project that you can do with js.
My friend, that I mentioned in the beginning, works at Gameloft. I don’t work at the same company, but we had a project in common and we need someone that knows js or jQuery. He used jQuery. That’s why I started to learn jQuery in deep.
In december I had to do a fancy app: reminder calendar(localhost not online) for a massage company. Each therapeut will login and put his bookings there. There are other tasks that I don’t know now, but if I don’t do the js part my friend will do it with jQuery. From what I know he knows js as well, better that jQery, but prefers jQuery, because is less code.

Please Fretburner, don’t understand me wrong, give me one (or more examples) project(s) that you can’t do it with jQuery, but only with js.

<canvas> is one example.

In its absolute simplest terms, anything the creators of jQuery didn’t think of. All it is, is a library of functions that its creators knew were commonly used by JS developers. If you open the source code for jQuery, you can go looking for the functions you’re used to calling, and just lift them straight out and into your own code. One of the common complaints would be the number of times a developer will include the entire jQuery library on a page (increasing its page weight) for the sake of one or two functions that could easily be done in plain vanilla JS, in a matter of a few lines. jQuery clearly still has its place, but you need to determine when that is.

Another I have seen is where they have used a dozen lines of jQuery that doesn’t quite work right to do what can be done in two or three lines of ordinary JavaScript.

After having written the latest version of my site to teach plain JavaScript with over 350 examples, I decided to add jQuery to it. That only needed 12 examples as each could simply refer back to a number of plain JavaScript examples to show the equivalent plain JavaScript to just about everything that jQuery can do - most of which now is not all that much different in the amount of code required as long as you don’t need to support antiquated browsers). Of course there are still hundreds of plain JavaScript examples there that can’t be done with jQuery (including all the canvas examples and some of the ajax ones - just to mention a few)

Ahaa, so now you came with the big guns :smile: . Thank you Chrisofarabia and Felgall for the examples. Like I said I am new in jQuery and I saw that on most projects that I had so far the clients said js or jquery. So my friend did all of them in jQuery. I will learn jQuery and when I get the project that I feel that js is the one to use I will go deeper in js, because I’m intermediate to js not senior.

Thank you for the compliment. I did do a fizzbuzz once and then backed off… :wink:

Did you do it the good way updating a text string or the bad way using extra if statements for the combinations?

Good (easy to add an extra option - commented out):

t='';
if(!(n%3))t+='Fizz';
if(!(n%5))t+='Buzz';
//  if(!(n%7))t+='Bazz';
return(t.length>0?t:n);

or bad (harder to add the same extra option):

// if(!(n%105)) return 'FizzBuzzBazz';
// if(!(n%35)) return 'BuzzBazz';
// if(!(n%21)) return 'FizzBazz';
if(!(n%15)) return 'FizzBuzz';
// if(!(n%7)) return 'Bazz';
if(!(n%5)) return 'Buzz';
if(!(n%3)) return 'Fizz';
return n;;

I’ll dig out my attempt when I get home, but I have seen quite a few versions now. I’d need to think about whether mine was nearer in structure to your too, but I know it’s not quite as concise.

The first such question I saw asked you to write a fizzbuzz function that would fit in a tweet. I took that to mean to make it as small as possible and so produced:

function fizzbuzz(n){return (n%3)?((n%5)?n:'Buzz'):(n%5)?'Fizz':'FizzBuzz';}

which is only 78 characters (the function name was provided so I couldn’t shorten it to fit in half a tweet).

Of course that way uses the “bad” way of setting the values and if you had five values to set instead of only two you’d have to use the other approach to fit them all into a tweet - just this way is a few of characters shorter for only setting two values.

I moved the discussion over here - Zen and the Art of FizzBuzz Maintenance

Ok I need to comment here. I’m someone who went straight into learning jQuery without learning vanilla JavaScript first. I think it’s a perfectly fine way of learning JS.

Yes with modern browsers, they can do a lot of what jQuery can do now with vanilla JS but JS is still a verbose language. The whole point of jQuery is to reduce the number of characters you as a developer need to type to do your job. The new “querySelectAll” command pretty much does the same thing now as the jQuery $(‘xxx’) selector. I’d much rather type “$” a million times though than “querySelectAll”.

If you learn jQuery first, you are learning a more succinct way of writing your code. Due to jQuery’s association with JavaScript, you end up learning JavaScript as well anyway. If you’re focus is on learning jQuery though you will only learn the stuff you need to know about regular JS rather than the stuff that jQuery can do with less code.

One thing I would recommend though is gaining a stong understanding of how JavaScript objects work. They are extremely useful but if you focus on learning jQuery you might not learn about them for a pretty long time. I’ve been doing front end web development for about 4 years now and I only just recently discovered how great JavaScript objects are.

On a side not, here’s a few more points on why it’s still worth using jQuery in your projects:

  • Think of all the plugins out there that require jQuery to work. Unless you want to scour the plugin source code, there’s no telling what jQuery functions it requires. By not including jQuery on your site, you’re locking yourself out of a lot of options.
  • If you load jQuery using the cloud hosted version rather than a locally hosted version, it is highly likely to already be saved in people’s caches so it doesn’t count towards load time in those instances.
  • I love the .slideUp() and .slideDown() commands for things like accordions. I could never give those up.