
jQuery vs vanilla JavaScript - Beau teaches JavaScript
video description
Date: 2022-03-14
Related videos
Comments and reviews: 7
Andy
I wrote a hundred lines of jQuery yesterday (including comments), then decided to use vanilla js instead. It took me 170 lines to write the same functionality. (NB: My vanilla js was slightly more efficient code because it was the second time I wrote the same app, so I had refactored some stuff). So I'd estimate the jQuery probably had about half the lines of code overall. The main reason why the jQuery was slightly leaner (in terms of lines of code) was because of the ability to chain statements together, rather than reselecting elements.
I think jQuery has a slight advantage in terms of readability... but it's not a big deal.
In my case, jQuery is probably still the best option, because I'm likely going to want to use jQuery UI as the app develops. Otherwise I'd have to rewrite some of the same functionality jQuery UI provides.
As with everything, I guess it all depends on what you need to do. If all you are doing is basic web enhancement stuff, vanilla js is perfectly fine. But the more you go beyond that, the more you appreciate out of the box solutions...
I think it's great though that js is evolving into a leaner and more powerful scripting language. And when you combine it with CSS3, you've really got a lot more power and flexibility than we had previously.
reply
I wrote a hundred lines of jQuery yesterday (including comments), then decided to use vanilla js instead. It took me 170 lines to write the same functionality. (NB: My vanilla js was slightly more efficient code because it was the second time I wrote the same app, so I had refactored some stuff). So I'd estimate the jQuery probably had about half the lines of code overall. The main reason why the jQuery was slightly leaner (in terms of lines of code) was because of the ability to chain statements together, rather than reselecting elements.
I think jQuery has a slight advantage in terms of readability... but it's not a big deal.
In my case, jQuery is probably still the best option, because I'm likely going to want to use jQuery UI as the app develops. Otherwise I'd have to rewrite some of the same functionality jQuery UI provides.
As with everything, I guess it all depends on what you need to do. If all you are doing is basic web enhancement stuff, vanilla js is perfectly fine. But the more you go beyond that, the more you appreciate out of the box solutions...
I think it's great though that js is evolving into a leaner and more powerful scripting language. And when you combine it with CSS3, you've really got a lot more power and flexibility than we had previously.
reply
Bagas
i am doing this usually
function $(selector) -
let elems = document.querySelectorAll(selector);
return elems.length > 1 ? Array.from(elems) : elems[0];
-
let elem = $('.someClass');
reply
i am doing this usually
function $(selector) -
let elems = document.querySelectorAll(selector);
return elems.length > 1 ? Array.from(elems) : elems[0];
-
let elem = $('.someClass');
reply
Jason
When you say to place that polyfill script tag at the top of your website, where exactly do you mean? In the head of the document? Does it matter what comes before or after it?
reply
When you say to place that polyfill script tag at the top of your website, where exactly do you mean? In the head of the document? Does it matter what comes before or after it?
reply
Charlie
Wish the dude would stop saying they're exactly the same at the beginning. They are not. Very very similar? Yes. Exactly identical? No. Beginners need precision to learn.
reply
Wish the dude would stop saying they're exactly the same at the beginning. They are not. Very very similar? Yes. Exactly identical? No. Beginners need precision to learn.
reply
Ptmp727
I personally don't find much of an advantage with Jquery, apart from a bit of advanced animation.
I find the javascript syntax very clear and easy to understand now,
reply
I personally don't find much of an advantage with Jquery, apart from a bit of advanced animation.
I find the javascript syntax very clear and easy to understand now,
reply
Liberation
so finally what's bad about using JQuery? it's clear that JS is almost as good as JQuery, but what are the exact reason why should i use the less convenient way?
reply
so finally what's bad about using JQuery? it's clear that JS is almost as good as JQuery, but what are the exact reason why should i use the less convenient way?
reply
Tarek
There are a lot of other jquery methods you didn't mention which is much harder to implement in plan js. For example, find and close, do they exist in plain js?
reply
There are a lot of other jquery methods you didn't mention which is much harder to implement in plan js. For example, find and close, do they exist in plain js?
reply
Add a review, comment















