The code you posted is used to test for a leap year.

The percentage sign is known as the remainder, or modulo operator and returns the remainder from the division of the second number into the first.
So in this case it checks:

Is the variable year divisible by four (i.e. there is no remainder)

and is the variable year divisible by one hundred

and is the variable year NOT divisible by 400

If these three conditions are met, the function returns true, otherwise it returns false.

Here we see the so-called ternary operator (?:) at work.
The syntax is as follows: test ? expression1 : expression2 test is any Boolean expression expression1 is returned if test is true expression2 is returned if test is false

So what is happening here is that if the variable month is less than or equal to two, then a value of zero is returned.
Otherwise a second ternary operator checks if the function “leap_gregorian” when called with the parameter “year” returns true.
If so, it returns -1, if not it returns -2

This whole line of the function will just equate to a numeric value, to be added to the return value.

i.e.

month <= 2 then the value will be 0

month > 2 and leap_gregorian(year) returns true then the value will be -1

month > 2 and leap_gregorian(year) returns falsethen the value will be -2

That JavaScript is a LOT more complicated than it needs to be - JavaScript has a Date object that provides the ability to do date manipulations without needing all those calculations.

The following does the same thing as all the code originally posted. Note that the code to get the Julian Day doesn’t use the code to determine leap years, I have just included that so you can see how much simpler it can be done in JavaScript than the complicated (and incomplete) formula the original code uses.

To determine whether or not a year is a leap year or not:

function leap_gregorian(year) {return ((new Date(year,1,29)).getDate() == 29);}

To convert a Gregorian Date into a Julian Day (including the correct fraction of a day - which the original code doesn’t do)