Skip to content

Instantly share code, notes, and snippets.

@cange
Created August 5, 2010 09:06
Show Gist options
  • Save cange/509456 to your computer and use it in GitHub Desktop.
Save cange/509456 to your computer and use it in GitHub Desktop.
Check if a given year is leap year. #learnjs
/**
* #learnjs
* Check if a given year is leap year.
* @param {int} [year] Year to be evaluated. If no date is used defines the client year.
* @return {boolean} Returns <em>true</em> is year a leap year, otherwise <em>false</em>.
*/
function isLeapYear (year) {
return (new Date(year || (new Date).getFullYear(), 1, 29, 0, 0).getMonth() != 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment