Learning JavaScript Libraries

jQuery has become the most popular JavaScript library by leaps and bounds, and is used on more than 40% of all websites in the world (see http://w3techs.com/technologies/overview/javascript_library/all ). It has gained its popularity for two main reasons: It's good at its job and it's namespace friendly, meaning that you never need to worry about jQuery getting in the way of your other code. You learn jQuery in this chapter and use it throughout the book.

You also learn another smaller library called Underscore.js. Whereas jQuery is concerned primarily with the manipulation of DOM elements and making Ajax calls, Underscore.js provides a number of utility functions that make JavaScript a more developer-friendly language, specifically targeted at functional programming. A self-proclaimed utility-belt for JavaScript, Underscore calls itself “ … the tie to go along with jQuery's tux.” It uses many of the same idioms as jQuery and is also namespace-friendly.

Do You Even Need a Library?
Technically, you could get by without any sort of JavaScript library. None of what you’re going to use jQuery or Underscore for is impossible to do with JavaScript directly. It just happens to be a lot less painful. Using JavaScript, you would end up with longer, less understandable code and need to write a lot more branching statements to handle different browser implementations.

Get Professional HTML5 Mobile Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.