Skip to main content
App management icon

This post is from the Apperian blog and has not been updated since the original publish date.

Last Updated May 25, 2011 — App Management expert

More Javascript and jQuery Mistakes

App Management
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

View more
Apr 30, 2020

Mobile Application Management: A Forward View

App Management
  IT Is Adapting in the Midst of the COVID-19 Pandemic The Coron ...
Read More
May 19, 2019

Sneak Peek: How Are IT Leaders Driving Mobile App Adoption?

App Management
Apperian conducted the The Mobile Enterprise Application Survey to fin ...
Read More
Jan 30, 2019

Part 1: App Security Should Be an Integral Part of Your DevSecOps Process — Not an Afterthought

Application Security
What are the key considerations and components of DevSecOps? The in ...
Read More
Nov 19, 2018

Breaking Down the New California IoT Law

Application Security
Recently California passed legislation regarding the security of all I ...
Read More
Contact Us