What Is jQuery? - dummies

By Steve Suehring, Janet Valade

jQuery is a JavaScript library. Okay, that might not make much sense. What’s a JavaScript library? A JavaScript library is a collection of code that you use when you want to get access to additional functionality or make life easier. jQuery does both.

jQuery is quite popular. Although there are no accurate statistics to show how often jQuery is used, cursory glances at popular sites show that jQuery is all over the web.

jQuery also makes cross-browser development easier. Though you haven’t seen much of it so far, support for JavaScript differs widely from browser to browser and from version to version. What works in Firefox might not work at all in Internet Explorer or might work completely the opposite.

A favorite example of how JavaScript support differs from browser to browser involves the handling of dates. There is a certain JavaScript function that returns the year. For example, assuming it’s 2008 when you call the function, JavaScript is supposed to return 2008 — but that isn’t always the case, depending on which browser you’re using.

When that function is used in Firefox or Safari, you receive the full year, 2008, as you’d expect. When you use JavaScript in Internet Explorer, you receive the number of years that have elapsed since 1900. When the year is 2008, you’d receive 108 back from Internet Explorer. Obviously if you’re trying to do any sort of date calculation with that value, it’s going to be wildly askew.

Which browser is right? It doesn’t really matter. What’s important is that the browser manufacturers read the JavaScript specification differently and in the end return different things for the same function.

Unfortunately, the date example is but one of many such examples (some much more serious than that) where browsers differ in how they implement JavaScript. The good news is that jQuery takes that complication away. jQuery’s functions figure out what browser is being used in an accurate way and then account for it in order to make the browser behave in a consistent manner.