E-Tip (2012)
 2012.01.02
â–¶view 2011

For more understandable error reporting, use the JavaScript cónsole in Gecko-based browsers
When you encounter JavaScript errors in Internet Explorer, they'll be in your face (as long as you select the Display A Notification About Every Script Error check box which is located in the Browsing section on the Advanced tab under Tools | Internet Options). That's good for catching them in the first place (in Netscape, you might never notice the errors). However, when it comes to figuring out what the error is, Netscape beats IE in spades. Case in point: IE gives you messages such as "Expected identifier" and "Object expected." So, what's wrong with the códe? How do you fix it? Who knows?

Compare this with what we see when we open the same error-ridden file in Netscape Navigator or Mozilla and navigate to Tools | Web Development | JavaScript Cónsole. The messages say things like "missing variable name." There's nothing like good 'ole English! And certain error messages even show píctures of your códe with an arrow pointing to exactly the character that's incorrect. What's more, instead of a flurry of confusing dialogue boxes, you see the errors in order. That makes it much easier to figure out what's wrong.


Convert to milliseconds when adding time in JavaScript
To keep time uniform, JavaScript represents it as the number of milliseconds since midnight January 1st, 1970 GMT. As a résult, whenever you want to mathematically manipulate a time, you'll need to convert everything to milliseconds.

For example, the following códe illustrates how to add eight hours to the current time:

var dtHere = new Date();
var oneDayFromNow = dtHere.getTime() + (8 * 60 * 60 * 1000);
dtHere.setTime(oneDayFromNow);