Why a JavaScript Developer Should Switch to jQuery

Published Jun 24, 2017Last updated Jun 26, 2017
Why a JavaScript Developer Should Switch to jQuery

Let me take back to the 1585 AD when the British established their first colony named Roanoke Colony in the United States. They faced very weak resistance from the Native Americans who were of no match to the Britishers. The British soldiers had guns and cannons while the Native Americans has just bows, arrows, swords and knives. Colonies after colonies were established and the US remained a slave of the queen for the next 300 years.

The World is always controlled by power and this also applies in every other area. Take for example the technology field – new technologies comes every now and then and replace the old one.

People who work on old technologies move to the new ones mainly because of the following 4 reasons –

  1. New ones are more powerful.
  2. They are fast and reduce your work load.
  3. Bring new features.
  4. Easy to learn and use.

Clearly Old is not Gold in Technology field.

JavaScript and jQuery Birth Dates

JavaScript came in the year 1995 and was an instant hit as it was new technologies much better than the technologies of that time. In 2006 jQuery came out and threw back its main competitor, JavaScript, from the throne. JavaScript at that time was 11 years old and does not stand any chance in front of jQuery (Just like swords does not stand in-front of guns).

What Happened to JavaScript Developers when jQuery was Released

It was just a matter of few months when JavaScript developers started moving to jQuery. The web was filled with jQuery articles and the new powerful features it provides – surely it also persuaded the developer to move to jQuery. Now after 12 years there are not even 10% JavaScript developers left today.

Why JavaScript Developers should Switch to jQuery

Today there are not more than 10% JavaScript developers are left other have moved to jQuery. If you are still a JavaScript developer then this article will tell you many reasons why you should immediately switch to jQuery.

1. You are not leaving JavaScript
The jQuery is JavaScript library which means you can still use all your previous JavaScript codes (if you want to). The for loop, while loop, AJAX, operators, etc will all remain, jQuery will enhance their working by adding new methods and features that can be used with these old JavaScript things.

For example: You can use the old JavaScript for loop, to loop through an array like this:

var myGods = ["Ram","Krishna","Shiva","Brahma","Vishnu"];
var arrayLength = myGods.length;
for (var i = 0; i < arrayLength; i++) {
    alert(myGods[i]);
}

With jQuery you can use a new Method .each() to loop through the array like this:

var myGods = ["Ram","Krishna","Shiva","Brahma","Vishnu"];
$.each(myGods , function (index, value){
  alert(value); 
});

So both of your codes will work.

2. Choose New Technology that is Powerful
jQuery is 100 times powerful than JavaScript. I say this because JavaScript codes sometimes fails to work correctly on different browsers and on their different versions. This is not so with jQuery as all your jQuery codes will work perfectly on all browsers and their versions.

There are hundreds of methods in jQuery that are powerful than the methods of JavaScript. Let us take the example of filtering an array.

Suppose I have to filter the array [1,2,3,4,5,6,7,8,9] to know only those numbers that are more than 5. The JavaScript code for this filtering would be.

var myNumbers = [1,2,3,4,5,6,7,8,9];
var result=[]
var arrayLength = myNumbers.length;
for (var i = 0; i < arrayLength; i++) {
    if(myNumbers[i]>5)
      result.push(myNumbers[i]);
}

In the above JavaScript code I have to loop through each element of the array then check whether each number is greater than 5. Finally if the number is greater than 5 then I add it to new array.

Moving to jQuery, the above code can be written like:

var myNumbers = [1,2,3,4,5,6,7,8,9];
var result=[]
result = $.grep(arr, function (n, i) {
    return (n > 5);
});

In jQuery I simply used .grep() method to filter the array. In the .grep() method function I just have to write - return (n > 5) and it automatically puts those number that are greater than 5 to the new array named result.

3. Migration from JavaScript to jQuery is flexible and can be done in Steps
Migrating your application code from JavaScript to jQuery is very flexible. You can do the migration in steps as both your JavaScript and jQuery codes can work together.

In the first step, migrate some of the JavaScript function to jQuery and include jQuery Methods wherever possible. By this I mean you can change the for loop to jQuery .each(), array filtering with jQuery .grep() and so on. Continue this for other JavaScript function one by one until all your JavaScript is converted to jQuery code.

You can always take your time, as you know both your JavaScript & jQuery code will work together and therefore your application will not be affected during migration process.

4. Code Less Do More
JQuery helps developers to reduce their codes by up to 70 to 80 percent quite easily. Complex works that require 50 to 100 lines of JavaScript can only be done in 5 to 10 lines of jQuery. This also gives a tremendous code development speed right to your fingers.

Take a small example – I have a paragraph element and I have to change its “color”, “font-family” and “font-size” in JavaScript.

This is what I will code in JavaScript:

<p id="myPara">Change my Color, font-family and font-size</p>
<script>
    document.getElementById("myPara").style.color = "red";
    document.getElementById("myPara").style.fontFamily = "Arial";
    document.getElementById("myPara").style.fontSize = "20px";
</script>

In jQuery I can do this work in just 1 line of code.

<script>
    $("myPara").css("color":"red","font-family":"Arial","font-  size":"20");
</script>

This is just a small example consider what jQuery can do for 10,000 lines of JavaScript code.

5. Faster Code Execution Good for SEO
jQuery is very fast in terms of code execution. The number of code lines drastically reduces in jQuery so it automatically gives a boost to the execution speed. Also being a JavaScript library, gives it the power of having hundreds of new methods specifically made to increase the code execution speed.

The faster code execution in your website will also increase the loading speed of your website – which is good for SEO. Search engines always give good rankings to fast loading websites. Certainly you will like to score on this factor.

6. Project Development Cost Decreases
We all know the project cost is directly proportional to the project development time. With jQuery you can bring down the project cost and can make your client happier than ever.

Consider this – if a client is billed $15/ hour for a JavaScript project and the total development hours are 200. Then the cost of project development comes to be $3000.

If you use jQuery then the development time will reduce by almost 50%, making the project cost just $1500.

7. Server Load and Hosting Charge Decreases
Today hosting companies like Amazon AWS, Google Cloud & Microsoft Azure change on factors like Bandwidth used, request made to the website and resource utilization.

Here jQuery helps in bringing down the hosting charge by reducing the bandwidth and resource utilization, thus saving few hundred dollars every year. It also reduces the size of web pages that decreases your server load.

I recommend you to use jQuery AJAX, which is very fast and request only the content that needs to be updated, thus drastically reducing bandwidth usage and load time.

8. Don’t miss your Project Deadline
With JavaScript you will always have to code more for doing things moreover you will also have to check all your codes in different browsers too. So there is a risk of missing your project deadline.

This is not so in jQuery, you code less do more, and your codes will work on all major browsers and their newest versions. Thus help you and your team to complete your projects on time.

9. Strong Open Source community
jQuery is an Open Source library with millions of developers contributing to it. You are never struck on any task. The internet has a comprehensive documentation and tutorials to get even an absolute beginner in programming and get the ball rolling with this library. There are also hundreds of prewritten plugins available for download tjat instantly speed up your development process.

10. jQuery uses Simple and Clean codes
jQuery separates HTML with your JavaScript Code. You don’t have to apply JavaScript event calls on HTML element any more. Take for example a button click in jQuery would be.

<button id="myButton">Click me</button>

<script>
    $("#id").click(function() {
        //code
    });
</script>

Clearly you can see I did not applied onclick="myFunction()" on the button like in JavaScript. It makes my code learn and simple.

Also ever team member of your project must know each and every line of cod. jQuery helps in this regards as the codes are clean and simple, making them understandable to every team member. No project development problem altogether.

Conclusion

So if you are a JavaScript developer time to move to jQuery.

Discover and read more posts from Yogi S.
get started