The Pros and Cons of JavaScript and jQuery
JavaScript is a scripting language and it is mainly used for website development. It is mostly used for client side validation. Over the years, JavaScript has become more popular amongst developers. Initially it was called LiveScript, which was invented by Netscape. Later it was renamed JavaScript.
The most common use of JavaScript is to write functions that are included in the HTML to interact with HTML elements. Some examples are
- Sending HTML page data to server using AJAX
- Animating HTML element
- Validating the HTML form
- Storing user information that may help for Web Analytic, Ad tracking etc.
- Browser detection
In brief, below are the pros and cons of the JavaScript.
Pros:
- Performance: As JavaScript runs on the client side it saves request time and bandwidth of web server.
- It is a lightweight scripting language and relatively easy to learn.
- As it run on the user machine, result and processing is relatively fast.
- Third party add-ons can be used to check code snippets.
Cons:
- Security issues - As JavaScript runs on the user machine it can be used to exploit for hacking purpose.
- JavaScript Rendering issues- JavaScript can be interpreted differently by different browsers.
jQuery: jQuery is a JavaScript library designed to simplify the client side scripting of HTML. A developer using this technology would like to write a minimum amount of code without affecting the performance and quality of the code.
Let's take an example,
We can get element value using,
JavaScript
document.getElementById(‘elementid').value
jQuery
$(‘#elementid').val();
jQuery Writes Less, Does More. JQuery library simply adds taste to JavaScript with simplicity and takes JavaScript to next level.
jQuery's syntax is very simpler than JavaScript. It makes it easy to navigate a document, select elements, handle events, and add effects. It also provides the ability to developer to create customized plug-ins. There are many JavaScript frameworks available but jQuery is the most popular. Large technology use jQuery for their web development needs. Companies like IBM, Mircorsoft, and Google just to name a few. Let's take a look on the pros and cons of jQuery.Pros:
- jQuery removes the headaches of cross platform Javascript compatibilities.
- jQuery is very easy to use as compared to other JavaScript libraries and JavaScript as well.
- jQuery has a large set of library/functions.
- jQuery has good documentation and help manuals are easily available.
- jQuery supports AJAX functionality.
Cons:
- You are no longer writing the native language, so your understanding of what is actually occuring may be limited.
- jQuery requires to include jQuery library files into project which takes space on the web server. But JavaScript can be used without adding any libraries. Also, if user wants include more jQuery libraries, version conflicts may occur.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)
Comments
Howard Lewis Ship replied on Wed, 2012/10/10 - 3:36pm
An odd note that "jQuery takes space on the web server". Perhaps you mean to say, "jQuery adds to the page rendering cost", in that it must be downloaded (if not already cached).
Further, you confuse "language" with "API". With pure JavaScript you are coding against the browser-provided native APIs (which vary between browsers considerably ... not just between IE and the rest of the world). With jQuery you are coding against an abstracted API that unifies the different browsers. I regularly work in both worlds, and can say what a significantly more pleasant experience it is to use the jQuery APIs than the native ones.
jQuery is a bit larger than some other similar frameworks, and you can see that they are trending towards some modularization, as well as jettisoning some support for very older browsers. That, and proper caching headers, can make a big difference in time-to-page-load (especially on subsequent visits).
That being said, unless you want to invest a huge amount of time in dealing with cross-browser DOM issues, you really don't want to be writing pure JavaScript. You will be opening yourself up to reinventing the wheel, rediscovering all the bugs, workarounds, and rough-edges found by the jQuery crew over the last six or more years, and excluding yourself from a large community of plugins, components, and documentation.
Robert Sanders replied on Wed, 2012/10/10 - 4:32pm
in response to:
Howard Lewis Ship
William Soprano replied on Wed, 2012/10/10 - 5:04pm
in response to:
Robert Sanders
Aaron Mc Adam replied on Wed, 2012/10/17 - 5:05am
I'm sorry, but this article lost all relevance to modern web development with the line "It is mostly used for client side validation."
Usman Ahmad replied on Wed, 2012/10/17 - 6:56am
I'd like to add that although jQuery is the way to go in most cases there are sometimes when you need that simple bit of three line javascript code to get the job done. In those cases, it would be an overhead to add the jQuery minified to your web pages.
So while every web developer SHOULD use jQuery (or some similar library) to liberate themselves from the inexhaustive amount of bugs caused by different browsers understanding of how javascript functions should be handled/work, knowing javascript itself would definitely be a huge advantage.
Josué Santos replied on Wed, 2012/10/17 - 7:14am