It always happens : you have some calculation to do with a date and you forget to calculate those friggin' leap years. Here's how to do it cleanly.

The first way

Almost every one use this simple rule : if it's divisible by 4, it's a leap year. So the code is
var isLeap = theYear % 4 == 0
Wait a minute, I forgot something! If it's not divisible by 100 but by 400 it is not a leap year… or maybe divisble by 100 and not by 400…

I can't remember that! Let's do it another way.

The one and only way

var isLeap = new Date(theYear,1,29).getDate() == 29;
Nice! That's something simple that I enjoy. Let's dissect it.
new Date(theYear, 1, 29)
This line simply create a date object that is initialized with the variable theYear. 1 is the month. As in java, the months are 0 = january and 11 = december (I hate that!). 29 is the last day of february when it's a leap year.
.getDate()
Returns the date part of a date (sic!). It means that for May 23, 2007, it will return 23.
== 29
That's the magic part of it. As I said in Mastering the date object in Javascript, there's a special twist that let you work with dates differently than in most of the languages that I used before. When you initialize a date at the 29th day of february on a non-leap year, it will simply use the date March 1, 2007. So a call to the getDate() function would return 1 and not 29.