Skip to main content
May 25, 2011

More Javascript and jQuery Mistakes

Continuing my last post, here are some more Javascript and jQuery mistakes that you should avoid.

These are common mistakes that can be tricky even for seasoned developers. Javascript is a language with a greater-than-average number of quirks and becoming familiar with them can make your life easier.

Trailing Commas

You must remove trailing commas from arrays and JSON, such as:

var foo = {"name" : "James", "score" : 150, }; // BAD

This code may work on some browsers, but will fail in older and less-compatible browsers. You must always remove trailing commas to be safe:

var foo = {"name" : "James", "score" : 150}; // GOOD

Date Object

The Javascript date object has some weird functionality regarding months. The Date.getDate() command returns the day of the month from 1 to 31, as you would expect. However, the Date.getMonth() function returns the month from 0 to 11. Similarly, the Date.getDay() is from 0 to 6. Don't be mistaken- 1/11 is February 11, not January 11.

Double vs. Triple Equals

'==' and '===' have one important difference- triple equals tests for type as well as equality. For instance, (0 == false) evaluates to true, and (0 === false) evaluates to false, because the objects are of different type. It's good practice to always use triple equals to ensure consistency and guarantee that you aren't doing implicit type conversion that may fail on certain browsers.

Not Using jQuery

When is the right time not to use jQuery? When you are doing something simple, or have a highly optimized string of code that needs to execute quickly. You need to test this code thoroughly in all browsers you support. There are other JS libraries out there, but none of them are as capable and supported. If you want to manipulate the DOM, use jQuery and don't stress about bugs!

Avoid these mistakes and be sure that your code is clean and bug-free.


More from the Blog
Mar 13, 2018

Latest Revelations Confirm Arxan’s Suspicions of Source of Apple Source Code Leak Issue

In early February news broke
Read more
Jan 11, 2017

Apperian Moving Up and To the Right as Part of Arxan Technologies

A letter from Mark Lorion, President & General Manager of Apperian. Dear Apperian Customers and Partners,
Read more
Dec 27, 2016

Predictions for 2017 - Where is Enterprise Mobility Headed?

The new year is around the corner and as we look back at 2016 it was an exciting year for the enterprise mobility market, ful ...
Read more