50

What is the main difference between JavaScript and jQuery. I know the minor difference like jQuery is high performance more reliable.

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
user3032819
  • 595
  • 1
  • 5
  • 6
  • 4
    jQuery is a library written in javascript, to make coding easier. My favorite part is their naming function like `toggle, show, hide, slideToggle, insertAfter`. – Praveen Nov 29 '13 at 10:06
  • jQuery is a library/framework built with Javascript. It is very popular because it (nearly universally) abstracts away cross-browser compatibility issues and it emphasises unobtrusive and callback-driven Javascript programming.[stackoverflow](http://stackoverflow.com/questions/3127938/what-is-the-difference-between-javascript-jquery-and-ajax-programming) – rynhe Nov 29 '13 at 10:07
  • 4
    "jquery high performance" you must have misread something – A. Wolff Nov 29 '13 at 10:08
  • 1
    The additional library that jQuery requires can dramatically increase loading time for those with slow internet. – SMBiggs Mar 29 '15 at 16:16

6 Answers6

43

jQuery is a JavaScript library.

Read

wiki-jQuery, github, jQuery vs. javascript?


Source

What is JQuery?

Before JQuery, developers would create their own small frameworks (the group of code) this would allow all the developers to work around all the bugs and give them more time to work on features, so the JavaScript frameworks were born. Then came the collaboration stage, groups of developers instead of writing their own code would give it away for free and creating JavaScript code sets that everyone could use. That is what JQuery is, a library of JavaScript code. The best way to explain JQuery and its mission is well stated on the front page of the JQuery website which says:

JQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.

As you can see all JQuery is JavaScript. There is more than one type of JavaScript set of code sets like MooTools it is just that JQuery is the most popular.


JavaScript vs JQuery

Which is the best JavaScript or JQuery is a contentious discussion, really the answer is neither is best. They both have their roles I have worked on online applications where JQuery was not the right tool and what the application needed was straight JavaScript development. But for most websites JQuery is all that is needed. What a web developer needs to do is make an informed decision on what tools are best for their client. Someone first coming into web development does need some exposure to both technologies just using JQuery all the time does not teach the nuances of JavaScript and how it affects the DOM. Using JavaScript all the time slows projects down and because of the JQuery library has ironed most of the issues that JavaScript will have between each web browser it makes the deployment safe as it is sure to work across all platforms.


JavaScript is a language. jQuery is a library built with JavaScript to help JavaScript programmers who are doing common web tasks.

See here.

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
37

jQuery is a JavaScript library, that can be used for communicating (selecting html elements, attaching event listeners, animations etc.) with the DOM, creating and consuming AJAX requests, as well as other things in a more easier way rather than using plain JavaScript. jQuery is written in JavaScript. It should be mentioned that browsers parse only HTML, CSS and JavaScript files. Hence, all JavaScript libraries/frameworks (jQuery, Knockout, Angular) are written in JavaScript or in languages like TypeScript that transconpiles to JavaScript (e.g. Angular 2). They provide you the opportunity to write less lines of code or to create interfaces following patterns like MVC (e.g. Angular), MVVM (e.g. Knockout) as well as other patterns, but under the hood, they are all result in a JavaScript file.

An example in order to understand why using jQuery you write less do more is the following.

Let we have the following input element

<input id="button1" type="button" value="clickMe"/> 

Also, let that we want when someone clicks on the button to be notified through an alert box showing to the user a 'Hello' message.

If we had to do this using plain JavaScript, we would have written the following:

document.getElementById("button1")
        .addEventListener('click', function(){ 
            alert("Hello");
        });

On the other hand, if we were using jQuery, we would had achieved the same result by just writing this:

$('#button1').click(function(){ 
    alert("Hello"); 
});

Using jQuery makes things more clear than using plain JavaScript for the same purpose. (write less do more is jQuery's moto)

Furthermore, jQuery handles pretty well the theme of browser compatibility, you can use their API pretty easily without wondering too much as if you should do in case of using plain JavaScript.

Below I have added snippets for the code above:

document.getElementById("button1")
        .addEventListener('click', function(){ 
            alert("Hello");
        });
<input id="button1" type="button" value="clickMe"/>

$('#button1').click(function(){ alert("Hello"); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="button1" type="button" value="clickMe"/>
starball
  • 20,030
  • 7
  • 43
  • 238
Christos
  • 53,228
  • 8
  • 76
  • 108
  • What is a javascript task? – Tibos Nov 29 '13 at 10:06
  • 3
    @Tibos Javascript gives you the opportunity to select DOM elements and adding to them certain behaviours, when you want to. Say for instance tha you have a element of type button and you want a box to be alerted when someone click on this element. In order to do so you should select the element, add a callback function for its click event and so on. All the above are js tasks. – Christos Nov 29 '13 at 10:09
  • Really a good example to understand the difference. – Gladiator Jul 16 '14 at 11:11
  • There is a slight spelling mistake in the method name "getElementById". I tried editing but it says the edit must me more than 6 characters ! – Ashok Dey Feb 21 '16 at 06:49
5

Javascript is a programming language whereas jQuery is a library to help make writing in javascript easier. It's particularly useful for simply traversing the DOM in an HTML page.

john-raymon
  • 306
  • 1
  • 7
  • 20
James
  • 2,195
  • 1
  • 19
  • 22
4

Javascript is base of jQuery.

jQuery is a wrapper of JavaScript, with much pre-written functionality and DOM traversing.

Zaheer Ahmed
  • 28,160
  • 11
  • 74
  • 110
3

jQuery was written using JavaScript, and is a library to be used by JavaScript. You cannot learn jQuery without learning JavaScript.

Likely, you'll want to learn and use both of them. go through following breif diffrence http://www.slideshare.net/umarali1981/difference-between-java-script-and-jquery

Indranil.Bharambe
  • 1,462
  • 3
  • 14
  • 25
3

jQuery is a multi-browser (cf. cross-browser) JavaScript library designed to simplify the client-side scripting of HTML. see http://en.wikipedia.org/wiki/JQuery

Orlo
  • 828
  • 2
  • 11
  • 28