Why would I want to use jQuery? [closed] - javascript

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
(I understand that someone else asked a similar question and it was closed as 'argumentative', but I'm really interested in understanding the arguments around this.)
I know JavaScript really well. I've been writing it professionally for years. I've internalized a lot of the cross-browser incompatibilities and sketchiness, know DOM manipulation like the back of my hand, have worked with some of the best web developers in the industry & picked up a lot of their mojo.
I've been checking out jQuery. I understand the point of a javascript library (how many times have I written animation, getElementsByClass, and hide/show functions?). But to be honest, it seems like a waste of time to learn an entirely new syntax that isn't less complex. It seems like I'd be bashing my head against a wall to learn an entirely new interface to the same old JavaScript.
I'm not technically an engineer, so maybe I'm missing something. Could someone spell out the tradeoffs of jQuery? Is it really faster to learn and understand jQuery syntax than to just learn JavaScript?

There are a few big benefits to using a framework over homegrown/handwritten code:
Abstractions. I'm sure you're very proud of the fact that you've slung enough JS to be able to write animations from scratch. You should be! However, abstracting common functionality away from yourself is actually very liberating. You just call the method and know the innards will be executed, and executed well. Even if you're very fast at writing the low-level stuff yourself, that's still time you've spent on that instead of solving today's problems.
Common language. Using a common framework is like speaking a common language. You can collaborate with other developers very easily, and each can pick up where others left off without friction. (Compared to stepping into an application which uses a homegrown library for the things jQuery can do.)
Experts. The people working on jQuery are JavaScript gods. I am really, really good at JavaScript, and you probably are too, but there's a big difference between normal good and jQuery good. A team of insanely good people are constantly poring over a small set of common functionality - tuning it, tweaking it, enhancing it to make it the best it can possibly be. That represents a huge number of man-hours a single person like you or me simply cannot reproduce, no matter how good we are. And if you are as good as the jQuery guys, you can only benefit by combining your talent with theirs and contributing to the jQuery codebase. It's a melting pot of insane talent.

I'm not technically an engineer, so maybe I'm missing something. Could someone spell out the tradeoffs of jQuery? Is it really faster to learn and understand jQuery syntax than to just learn JavaScript?
jQuery is more than "just another interface" to Javascript. It allows you to express yourself in ways that are more compact and succincter than the corresponding Javascript implementation. At the same time, it's clearer and much more powerful. Specifically, the benefits you get include:
Expressiveness. jQuery is essentially a DSL for DOM manipulation and querying. This specificity is a major source of its utility and effectiveness.
Cross-browser. To a very large extent, jQuery is "write once, run anywhere". Even in 2009, this is still a surprisingly rare feat for web-based platforms. It's gratifying and relieving to know that you won't have to waste time debugging obscure problems on IE6 (well, most of the time).
Highly complete documentation. As a developer, I prize APIs and frameworks that have taken the time to spell out what all the moving pieces are supposed to be doing. Nothing is more encouraging than knowing that (1) things are stable enough that writing documentation isn't an attempt to hit a moving target and (2) things are useful enough that they've attracted enough people to flesh out the documentation fully.
In sum, the difference between Javascript and jQuery is analogous to the difference between assembly and higher-order programming languages. Although they're both technically both "an interface to machine language" and can both do similar things, the latter is considered far more powerful because of how easy it is to represent things and develop rapidly.

One thing I don't see mentioned is that the library is written to work cross browser on a wide range of popular browsers and platforms: IE6+, Firefox 2+, Safari 3+
That alone is reason enough to use jQuery then to write your own JavaScript and have to worry about cross browser issues yourself.

You can't learn jQuery without learning JavaScript, and you can't be a jQuery guru without being a JavaScript guru.
That said, it really is much faster to do things with jQuery than with "bare metal" JavaScript. Moreover, the way one works with jQuery is at a far more abstract level than the way one works with "bare metal" JavaScript. In addition, the jQuery syntax is very basic and not at all hard to learn, although the way you think about jQuery is very different from the way you think about "bare metal" JavaScript but enables you do to much more, much more rapidly.

community support
other developers writting and testing code, make it possible for you to do things you simply do not have time to do. Its not about doing anything you do not know how to do, its about doing things quickly, efficiently, and of very high quality (its already been tested).

From the sounds of it, you know much of the same stuff that jQuery knows about the DOM, and I can only assume you've built-up a nice DOM toolset for yourself over the years that incorporates all of this knowledge. In short, No, you don't need to use jQuery. However, some of the rest of us do not know as much about the DOM, and jQuery levels the playing field so we can get on with getting work done for our clients.
That is not to say you should not learn jQuery (as opposed to using it). You may pickup a few things you didn't know. The 3 main features that distinguish it from other DOM libraries (including your own probably) are:
built-in support for CSS selector syntax, useful for finding elements
methods that operate on the set of wrapped elements
chaining. Every method in jQuery.prototype (with "setter" behaviour) returns this
Personally, 1) and 3) don't hold a high premium. But 2) turns out to be huge for me. I never realized until jQuery how much my code tended towards operating on a set of nodes rather than a single node (if someone would have asked me I would have guessed the opposite tendency). 2) virtually eliminated all for loops from my code (or .forEach or however else I tended to abstract it), which was actually quite liberating. Now I notice it's the rare occasion where my code must operate on some single element.

Speed of development and turnaround of code.

One thing I haven't seen mentioned in the other answers is that, eventually, someone else is going to have to maintain your code. If it's all custom, they'll have a rougher time of it than if a more standard library is used. If that's not of any concern to you, and you don't think you're likely to need any of the really slick jQuery modules, then keep on with what you're doing.

For me, there are several benefits, like speed of development, etc.
But at the end of the day, it boils down to one thing:
It removes a HUGE amount of the cross-browser BS that can eat up so much time and resources, so I don't have to deal with it

jQuery allows you to write shorter, cleaner code that's easy to understand. Many people use it, so there are many plugins that work along with it, minimizing bloat. The same may not be true of your own personal library.

If you know JavaScript really well you should also know that jQuery's syntax isn't different from JavaScript's syntax.
What you might be referring to is the chaining idiom (used everywhere in jQuery) which seems to make things look very different from other sort of code. Well there's a reason for that, it's because it bonds really well with how the DOM works.

If you truly know JavaScript, you'll be at running speed with jQuery in under a week's time. If you don't already know your way around JavaScript, adding a layer on top might do more harm than good. But that's just like anything else!
You're going to be writing better looking and easier to understand JavaScript at a faster pace and only once — not once per browser. Downside? You're going to tack on another ~50KB of JavaScript. That's what caching is for :)

Jquery is javaScript in the hand of the designer.
It is as easy as writing CSS styles on an element.
Also Jquery is the easiest to understand, write maintain, add plugins.

I was working on a gallery program for a client (which is now exhibiting inexplicable behavior in IE6 and 7 - surprise, surprise - but I found that when I switched from bare-metal Javascript to jQuery a lot of the work got much easier. To me, it makes available the CSS view of the DOM while writing Javascript - which makes traversal and manipulation much more intuitive. Also, the cross-browser compatibility and brevity is wonderful.

It doesn't really matter if jQuery is great or awful. It's the powerhouse JS library now, used on a huge number of pages, and future browsers will have to accommodate it or be seen as themselves buggy.
What I don't like about jQuery: I'm not that thrilled about how it ignores mobile phone browsers in its test suites. It gets pulled in on all kinds of pages on mobile phones, and yet it makes no effort to ensure it works well on them.

jQuery degrades gracefully and it's one of the fastest (not THE fastest anymore though):
http://mootools.net/slickspeed/
There are many other frameworks out there, and whichever you choose, you probably wouldn't go wrong, but having uses jQuery myself, I'd definitely recommend it.
:)

Related

Removing jQuery for performance reasons justified?

I am on a new project and our job is to rewrite an e-commerce website that is having performance problems on mobile devices.
We are re-writing the javascript based on a more object-oriented/modular architecture which I think is great! However my team lead said that we should remove all the jQuery calls and replace with javascript like so domElem.querySelectorAll(query) , which has better performance. I understand jQuery does some kind of caching in the background which can create memory issues.
I am a little sceptical of this, firstly because it seems like a case of 'premature optimization', that is, we should find the bottle-necks first before we re-write anything. And secondly I haven't found anything on the internet that says that jQuery has significant performance problems.
The current website does have a lot of overlapping dom branch queries which I think creates a lot of redundancy. That is there is too much querying happening, and on our new architectual approach we are restricting our object/module to fewer dom queries and more targeted dom queries which is great. This does need to be re-written.
But whether or not we use domElem.querySelector(query) or $(domElem).find(query), I can't see there as being much of a difference. Is my thinking right?
Some tests are done here (check other revisions as well). Good detailed discussion is done here over pros and cons of using jquery over javascript.
Also want to point out that jquery doesn't do any caching of selectors.
The thing we often forget because of using Javascript frameworks all the time is that jQuery is not a framework.
Obviously, if you do the exact same one-operator action using the jQuery '$' object and using a direct DOM method like getElementById, the latter will be noticeably faster as jQuery itself is written in Javascript and does a lot of background stuff.
However, nothing (except code readability) prevents you, as a developer, from combining jQuery with plain Javascript: using plain Javascript wherever possible and only using jQuery functions that provide complex functionality and take some time to write and optimize from scratch. There are a lot of those in jQuery: providing browser-independent css, serializing object and doing lots of other cool stuff.
It depends on the application but usually performance troubles are related to badly-designed algorithms, not the use of jQuery.
In any case, if your application does a lot of DOM-manipulation, it may be worthwhile to re-write it using plain Javascript and test. Keep the library, just don't use it for simple operations you can easily write without it.
If your application is heavily-reliant on jQuery functions with complex functionality, removing it is out of the question.
I myself use this combined approach: everything simple written in Javascript with jQuery functions for stuff that is difficult to implement.
Also, a good place to dig around if the app has troubles with performance is the DOM-manipulation. Those operations are very heavy compared to almost everything else in Javascript. You may be able to cut down on time by rolling several operations into one, building finished objects with one constructor, instead of creating empty ones and assigning properties one-by-one, etc.
Sorry, if the answer is a bit vague but it's difficult to be precise in this case without seeing the code and running tests.
Let me quote Uncle Bob about this discussion "Architecture is about intent, we have made it about frameworks and details"
Premature optimizations needs to be considered carefully.
They often result architectural decisions that are not easily revertible.
They introduce code optimizations that are usually specific to the problems they solve, which makes the code less abstract thus hard to
maintain, and more complicated thus prone to more bugs.
They tend to be prejudice and not objective, sometimes without any real comparison to other alternatives.
The problems they are trying to solve tends to be overestimated, to the degree of non-existent.
I'm not a big expert on Web development but if possible, you should always push this kind of decisions to the end by separation of concerns, and good abstraction.
For example over the parts that generate the java-script code you can have an abstraction of JavaScriptWriter, and use different frameworks. This way you can use JQuery at the beginning, test the system and only then replace parts you know to be inefficient.

What are some empirical technical reasons not to use jQuery? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Context:
I am astounded by the number of front end developers that hack at HTML, Javascript and CSS all day long and that ignore tools like jQuery ( or other equivalent helper frameworks ) and refuse to use them. I am not talking about JavaScript gurus, I am talking about in the trenches every day Joe production developers. I get a lot of arguments that are more like excuses or personal opinions that I don't think have any technical merit, I want to make sure I am not missing something.
Question:
What are some empirical technical reasons not to use jQuery?
I am not looking for religious or dogmatic arguments or subjective opinions "like some other framework is better", consider jQuery the straw man for all comparable frameworks in the question.
Update 2015:
In this answer from 2011 I'm talking about libraries like jQuery, YUI
or Prototype. Today in 2015 that reasoning is still applicable to
frameworks like Angular, React or Ember. In those 4 years the
technology progressed tremendously and even though I see considerably
less prejudice against React or Angular than I saw against jQuery or
YUI, the same kind of thinking - though to a lesser extent - is still present
today.
Update 2016:
I highly recommend an article published few days ago:
Why jQuery? by Michael S. Mikowski, author of the Single Page Web Applications book
That article is basically a very detailed answer to this very
question. Had it been available when I was writing the answer below - I would have definitely quoted it.
Original answer:
I'll answer about jQuery but those are the same arguments that I've heard against using YUI, Prototype, Dojo, Ext and few others. Main arguments that I've heard:
file size, which in fact is 84.6 KB in case of jQuery 3.2.1 - probably smaller than the logo on an average website and can be served from Google's CDN which is likely to be already in the cache of most of your visitors. As using jQuery always means smaller file size of your own JavaScript files, it can actually mean smaller download, even if not already in the browser cache.
speed - writing pure JavaScript may be faster, but writing portable JavaScript seems to be impossible for most of the people. A website that is faster but doesn't work on every popular browser is useless in the real world. Besides jQuery uses some pretty heavy optimizations to actually be pretty damn fast and keeps getting even faster with every release, so it's actually not so easy to write faster code by hand for anything other than trivial examples.(*)
"intellectual property" - a company is scared using someone else's code - while in fact jQuery is open source and free software that is used everywhere from your grandma's blog to Amazon, from Twitter to Bank of America, from Google to Microsoft - if they can use it then any company can use it.
I can't remember hearing any other argument being used seriously.
(*) Here's a trivial example: getElementById('someid') vs. jQuery('#someid')
Is using getElementById faster? Yes. And of course everyone always checks the parentNode to catch when Blackberry 4.6 returns nodes that are no longer in the document, right? jQuery does. And everyone handles the case where IE and Opera return items by name instead of ID, right? jQuery does. If you don't do it then your code is not portable and you introduce subtle bugs that can be very difficult to find. And getElementById is the most trivial example that one could possibly find - don't even get me started on events and AJAX and the DOM...
Update:
There is actually a fourth result of asking why someone doesn't want to use jQuery. I forgot to put it on this list because it is not really an answer but rather the lack of any answer. The comment I got yesterday reminded me about it. This is hardly a "technical reason" to be added to the list but may be interesting nonetheless and may actually be the most common reaction.
What I personally suspect to be the main underlying reason to all of those reactions, though, is what I believe to be the biggest obstacle to progress in computer science: "I don't want to use it because I never did, therefore it must not be that important."
It was once the reaction to optimizing assemblers, compilers, structured programming, higher level languages, garbage collection, object oriented programming, closures or pretty much everything that we now take for granted — and today it's AJAX libraries. Maybe some day no one will remember that we once used to manually interact with the raw DOM API on the application level like now no one remembers that we once used to write programs using raw, unadorned, inscrutable hexadecimal numbers.
jQuery expresses everything in a DOM-centric paradigm which can be misleading and doesn't require any need to express things in an application pattern.
Many developers wind up programming themselves into a corner with this DOM-centric pattern and eventually realize they haven't created anything extensible or reusable.
Rebecca Murphey has a great write-up of her own switch to Dojo from jQuery - the blog post is more about why not jQuery versus why Dojo.
One reason not to use a framework - and this is an extreme edge case - is when writing embeddable code for another website, such as a banner. Arbitrarily inserting some complicated library or another will be polluting the namespace and potentially breaking someone else's site. Not that I wouldn't put it past some advertisers to try anyway, the pond-sucking scum, but I digress...
I disapprove of adding a framework when one is already present and equally capable. I see it all too often and it's my pet hate, I see it as unwarranted bloat. That is another question entirely.
Other than that I cannot think of a justified reason not to.
filesize - but really, beyond that, it's an absolute god-send for cross-platform javascript and browser differences. You would have to have some very good reasons not to want it in your toolkit (or be a fundamentalist developer idiot).
They can't justify the filesize (even though it is probably less than script which doesn't utilise the abstractions provided).
They don't want to rely on third party tools.
Their business does not want to run any libraries (for whatever reasons).
Their business does not want to run any JavaScript code not written by their employees.
Learning: To actually code everything, and learn more. (Rather than using pre-coded stuff)
Size: jQuery has TONS of features you might not need, why make the user download so much code if it's not going to be used?
Alternatives: at this point, there are dozens of more powerful, well structured web frameworks out there.
Flexibility: Although jQuery is really flexible, you might need something it doesn't provide.
By all means, I like jQuery, but there are some reasons not to use jQuery:
Download size/bandwidth: jQuery 1.5 is now over 200K uncompressed, for some the size of the library is too much to justify the benefit.
Performance: Writing native JS will always be faster than abstracting it behind a library.
Added complexity: Many people will download the entire jQuery library when really they only need a few neat features from it.
Application Dependencies: Introducing dependencies always has its hang ups. If there is a bug in jQuery, you can debug and edit the file, but upgrading later introduces problems. You could leave the bug, but now you are dependent on jQuery's time table for a fix, not your own.
Because quite often it's just unnecessary.
if all I want to do is validate some input, or hilight some field then it's just as easy to write simple javascript / dom code. And jQuery doesn't really help in such simple cases, so the question should be why use it?
Clearly there are many cases where it is very useful, but sometimes people seem to use it for no real reason too.
I would prefer to use jquery for dom manipulation or traversing the dom , which is really easy with jquery . Moreover, attaching an event or event delegation are so easy using jquery or other framework otherwise you have to write custom event attachment for IE or non IE browsers etc.
But it has some performance penalty when you use $.each instead of vanilla JS for and array.push()...
other issues like if you bind an event and remove that without unbind it will have memory leak....
My conclusion is only use any framework for complex dom manipulation and rest use vanilla JS
Why not use jQuery?
I can't think of a good excuse to use vanilla JavaScript over jQuery (aside from the intimidation factor of learning something new), but some people prefer other JavaScript frameworks (like the excellent MooTools) due to the philosophical differences between them.
Some people simply don't like jQuery's DSL-ish syntax, but they recognize the importance of using a robust JavaScript framework.
Personally, I love jQuery, but I know people who use other frameworks and are no less productive.

jQuery vs. javascript? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I recently stumbled upon some javascript forums (sadly, link is lost somewhere in the universe), where you could feel real hate against jQuery for not being... any good?
Most arguments seem to make sense actually.
Now, I really like jQuery, mostly for letting me concentrate on things I want to do rather on browser inconsistencies and it actually makes AJAXing with cool (or overused?) effects fun.
But if really is something rotten in the core of jQuery, I don't want to rely on it the way I actually... rely on it.
I don't want to start yet another argument over which framework is the best... but... Which framework is the best (joke)? As a case usage, think about small to medium web and it's administration.
I'm just trying to figure out, if stuff in some framework or pure javascript with few mine functions really makes difference.
Edit:
I actually tried to have a normal objective discusssion over pros and cons of:
Using a framework over pure javascript and
jQuery vs. others,
Since jQuery seems to be easiest to work with with the quickest learning curve. However, some people just don't understand it and think that I'm starting yet another flame (what I am not). I am actually voting to reopen this question.
Also I'm really interested in:
Does jQuery heavily rely on browser sniffing? Could that be a potential problem in the future? Why?
I found plenty JS-selector engines, are there any AJAX and FX libraries?
Is there any reason (besides browser sniffing and personal "hate" against John Resig) why jQuery is wrong?
jQuery actually, as most used, stands for other frameworks also.
It's all about performance and development speed. Of course, if you are a good programmer and design something that is really tailored to your needs, you might achieve better performance than if you had used a Javascript framework. But do you have the time to do it all by yourself?
My personal opinion is that Javascript is incredibly useful and overused, but that if you really need it, a framework is the way to go.
Now comes the choice of the framework. For what benchmarks are worth, you can find one at http://ejohn.org/files/142/ . It also depends on which plugins are available and what you intend to do with them. I started using jQuery because it seemed to be maintained and well featured, even though it wasn't the fastest at that moment. I do not regret it but I didn't test anything else since then.
Personally i think you should learn the hard way first. It will make you a better programmer and you will be able to solve that one of a kind issue when it comes up. After you can do it with pure JavaScript then using jQuery to speed up development is just an added bonus.
If you can do it the hard way then you can do it the easy way, it doesn't work the other way around. That applies to any programming paradigm.
jQuery like any other good JavaScript frameworks supplies you with functionality independent of browser platform wrapping all the intricacies, which you may not care about or don't want to care about.
I think using a framework is better instead of using pure JavaScript and doing all the stuff from scratch, unless you usage is very limited.
I definitely recommend jQuery!
"I actually tried to had a normal objective discusssion over pros and
cons of 1., using framework over pure javascript and 2., jquery vs.
others, since jQuery seems to be easiest to work with with quickest
learning curve."
Using any framework because you don't want to actually learn the underlying language is absolutely wrong not only for JavaScript, but for any other programming language.
"Is there any reason (besides browser sniffing and personal "hate"
against John Resig) why jQuery is wrong?"
Most of the hate agains it comes from the exaggerated fanboyism which pollutes forums with "use jQuery" as an answer for every single JavaScript question and the overuse which produces code in which simple statements such as declaring a variable are done through library calls.
Nevertheless, there are also some legit technical issues such as the shared guilt in producing illegible code and overhead. Of course those two are aggravated by the lack of developer proficiency rather than the library itself.
Does jQuery heavily rely on browser sniffing? Could be that potential problem in future?
Why?
No - there is the $.browser method, but it's deprecated and isn't used in the core.
I found plenty JS-selector engines, are there any AJAX and FX libraries?
Loads. jQuery is often chosen because it does AJAX and animations well, and is easily extensible. jQuery doesn't use it's own selector engine, it uses Sizzle, an incredibly fast selector engine.
Is there any reason (besides browser sniffing and personal "hate" against John Resig) why jQuery is wrong?
No - it's quick, relatively small and easy to extend.
For me personally it's nice to know that as browsers include more stuff (classlist API for example) that jQuery will update to include it, meaning that my code runs as fast as possible all the time.
Read through the source if you are interested, http://code.jquery.com/jquery-1.4.3.js - you'll see that features are added based on the best case first, and gradually backported to legacy browsers - for example, a section of the parseJSON method from 1.4.3:
return window.JSON && window.JSON.parse ?
window.JSON.parse( data ) :
(new Function("return " + data))();
As you can see, if window.JSON exists, the browser uses the native JSON parser, if not, then it avoids using eval (because otherwise minfiers won't minify this bit) and sets up a function that returns the data. This idea of assuming modern techniques first, then degrading to older methods is used throughout meaning that new browsers get to use all the whizz bang features without sacrificing legacy compatibility.
Jquery VS javascript, I am completely against the OP in this question. Comparison happens with two similar things, not in such case.
Jquery is Javascript. A javascript library to reduce vague coding, collection commonly used javascript functions which has proven to help in efficient and fast coding.
Javascript is the source, the actual scripts that browser responds to.

Can I learn how to use jQuery with just a basic JavaScript experience?

The question is: Is it bad to learn how to do special effects, table sorting, etc, using jQuery instead of learning the bits of code that bring that alive with pure javascript?
I have previously addressed a similar problem in a question, but I missed adding this extra inquiry!
Yes you can. Doing it in JQuery isn't bad. Everyone uses some sort of Javascript library. I love JQuery. Your odds of making things that work in all browsers go up quite a bit, you get the UI done quicker, etc.
Though having a bit of Javascript knowledge is good, because when things go wrong you want to be able to debug the problem.
JQuery.com has lots of good tutorials.
You really should use jQuery; it will allow you to spend more time adding features instead of trying to make your code work in every browser (Note that even jQuery is not a silver bullet; you'll still have some cross-browser headaches in any non-trivial web app, especially if you need to support IE6).
There's no point in turning your back on new tools and libraries just to "stay close to the metal".
If you're afraid of lowering your value in your boss' eyes, look at it a different way. Would you prefer to hire a programmer who spends all of his time working around browser bugs, or a programmer who uses jQuery and finishes his projects faster because of it? Remember that managers are trying to ship products and make money, not simply hire elite programmers.
Personally I was recommended to learn JS before learning jQuery. But started off with jQuery, and can make pretty much with it without to much JS experience. What you do need to know of JS you can just google it and learn it when needed ;)
jQuery is fantastic for us that doesn't take the time to learn everything about JS
Personally, until the beginning of this year, I used to limit my use of javascript to only helping aid the user with things like web forms.
However, after playing around with jQuery for no more than a few days, I realised how much easier it made achieving javascript effects and functionality. Now I pretty much use jQuery on most web pages, a lot of the time, just to add nicer UI effects.
A background knowledge of raw javascript will never go amiss and you will almost certainly still have to mix it in with your jQuery scripts, but when you run into troubles, nearly every problem I've had, had a solution already posted on Stack Overflow or just on Google.
Not a very technical answer, but as an intermediate programmer, and javascript newbie I've had no problems learning to work with jQuery. The documentation and community are very helpful.
I think you should set yourself a goal of knowing javascript well enough to be able to author a plugin if you need it in your favorite framework. While using a framework is almost always the right way to go, there will be times when you can't find a plugin that does exactly what you need. At that point you need to know javascript well enough to be able to adapt a plugin to your needs or write your own.

Is it a good idea to learn JavaScript before learning jQuery? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Is it a good idea to learn JavaScript before learning a JavaScript framework library such as jQuery, Prototype, etc.?
Sometimes I find myself struggling because I feel I don't know JavaScript as well as I should.
An emphatic YES. It won't take as long to learn as you fear and the rewards will be more than worth it.
Sometimes I find myself struggling
because I feel I don't know Javascript
as well as I should?
I think you answered your own question.
I'll go against the grain and say that, while ideally you would become proficient in JavaScript before learning jQuery, you can probably make great progress on both fronts by jumping in and coding using the library.
One of jQuery's strengths is that it makes it easier to do certain things in the browser. You can get a lot of real work done by cutting and pasting and adapting other people's code, so why not start doing that? As you go, when you encounter an idiom you don't quite understand, dig around and find out what it means or how it works.
Over time, you will become a master of both JavaScript and jQuery.
If you have any kind of programming background, a good book to read to get you up to speed quickly on JavaScript is Douglas Crockford's, JavaScript: The Good Parts.
Long as you learn the BASICS in Javascript; HTML document traversing, event handling, etc... you should have no problem learning jquery.
Then from learning the basics you will understand how Jquery is to help you do the things that javascript can do, but with less work.
The answer to your question is a definitive yes. jQuery, Prototype and the rest serve to overcome cross-browser headaches and ease AJAX, UI behaviours, DOM operations etc. You'll end up with some pretty bad code if you are just copy/pasting snippets or have no real understanding of Javascript.
As a litmus test, you should be able to follow everything that is said in this wonderful re-introduction to Javascript. It's a bare minimum for writing good code and may require some more Googling on your part. Only then should you read Willison's equally good introduction to jQuery.
That should provide you a good start to build upon. And then if you feel up to it, you can start digesting Crockford (start with Douglas Crockford — JavaScript: The Good Parts).
Yes it a good idea because jQuery provides you with shortcuts for some methods and effects. By learning JavaScript you get the complete idea about how jQuery is working. It will help you to solve bugs and issues in future, when you will be working on a project.
Call me old-fashioned, but I think it is best to learn the basics of one tool before moving on to its advanced cousin -- much like being competent with a handsaw before moving on to a circular saw.
If you are struggling, you've answered your own question. I feel you'll be better equipped to make good use of JQuery once you are comfortable with JavaScript.
When I started my switch from VBScript to JavaScript I was immediately enthralled with Jquery. After a short while I started to really understand how JavaScript and Jquery interacted with each other and I became a little confused and frustrated. My issue was with the desire to use the simplicity of Jquery but I felt like I was cheating myself by not learning JavaScript first.
It turned out that I learned both at the same time. As I wrote JQuery routines I found the need to learn JavaScript in order to understand why things worked the way they did and to help make certain Jquery routines work correctly.
I am still learning JavaScript and Jquery but I am much less concerned about becoming a master of JavaScript as I know my understanding will grow as it needs to. It definitely helps to have some basic understanding of JavaScript but I would say you should focus on learning how to accomplish specific tasks and not on learning JavaScript before JQuery...
My $0.02 worth.
As I see it, jQuery is nothing but a framework to make your life simpler. jQuery itself is written in javascript. So it helps to learn javascript.
Mind you, you need not be a master but should be able to make the necessary changes /work arounds, when what you can do with jQuery alone is not sufficient.
To some degree, but don't get hung up on object oriented programming like in the java world (in javascript it's prototyping anyway). It would help in the long run to have a good understanding of closures/anonymous function and how the special variable "this" is used (particularly with regards to events such as click) and how functions like "apply" work. I'd also make sure that you really understood CSS selectors as they are a central feature of jQuery and pretty much every other JS framework out there.
You're also going to need to be familiar with how to use the full functionality of firebug.
I'd also assume you have a basic understanding or knowledge of how the DOM works.
That's the start of tinkering in Javascript.
The value proposition for jQuery (or any other framework) doesn't only come from what it does with javascript. It also builds on the DOM, HTML, and a number of language-agnostic patterns. And you don't need to understand it all in depth to find frameworks useful. Of course, you'll be better off if you know all the pieces, but we all need to start from something less.
I learned jQuery and javascript simultaneously, and it worked quite well for me that way.
I think the question isn't so much which to learn first, but more to the point, you need to expect to become increasingly familiar with all the pieces and how they work together.
To me it's somewhat (not entirely) the same question as what you need to know before starting with WebForms. Sure it's better if you're already comfortable with C# (and the same DOM and html), but it's legitimate to use WebForms as a vehicle for your education. Same thing can be said for frameworks.
Suppose you should know the following about Javascript:
How to calculate the X and Y element offset for the absolute/relative positioned DIV for browsers IE6-IE8, FireFox, Opera, Safari (each of the browser has different model for this particular case).
What is closure and how to create it.
How to create onLoad event in the browsers listed above.
Have an example of the HTML/Javascript code where you have pure HTML code like
Remove
and javascript code that add special handlers in automatic mode for A tag using "rel" attribute.
After you get acquainted with this you may use jQuery library that hide the complexity of this :)
Regards,
Pavel
I think learning events the document object model, and JavaScript forms programming is enough to get started in jQuery.
Of course, it goes without saying. How can you use jQuery if you don't learn JavaScript first? After all, jQuery is nothing but a library for JavaScript.
Yes.
You obviously don't need to learn everything about JS. But at least learn the basics, and try to learn some best practices.
For me the trickiest part about Javascript is all the different implementations of it in the different browsers. But there are certain things you can do to help yourself avoid some of those problems. For example, it's usually preferred to use document.getElementById() to access elements in the DOM since it essentially works the same way in all modern browsers. Also, it's almost always best to use feature detection rather than browser detection. Little things like that go a long way in avoiding problems in specific browsers later on.
Fortunately JQuery was written pretty well for cross-browser compatibility, but there may be times when you don't want to use it directly and you may have to rely on your JS skills.
There are really two seperate aspects to JavaScript within the Browser. First, the JavaScript Language, and second the HTML DOM that allows you to manipulate the page using the JavaScript Language.
That said, then YES you should spend time learning the JavaScript Language. I recommend picking up a copy of "JavaScript: The Good Parts" by Douglas Crockford.
Now as to the second part, the HTML DOM. You really don't need to focus too much on learning the ins and outs of the HTML DOM if you are going to use a framework like jQuery. Just do things the "jQuery way" and then pick up as much HTML DOM as is necessary along the way.
Just enough to debug your code. Otherwise, you will never be able to figure out what's not working.
Learning JS would make life easier for coding JQuery but I don't see why you should necessarily learn it first. You'll just have to learn it eventually.
My first thought was that It's always good to learn something new and Javascript is becoming ubiquitous (now is on the server side too ).
It's seems that you have still not decided the best answer for you and AFAIK this question was posted before March 21 ... I see plenty of time to read at least this that was written by a very talented guy.
If you study javascript you will never come to SO asking question like:
What the keyword this mean in the contest of my snippet of code?
But if you always are in a hurry, without having time to improve your code and If you never have to build jQuery plugins go without Javascript.

Categories

Resources