Understanding isPrime function from Wikipedia, a function that determines if a number is prime I know there are several questions on how to determine if a number is prime but none of them help me understand this particular implementation on Wikipedia, https://en.wikipedia.org/wiki/Primality_test 
I understand the two if statements, not the for loop. Specifically, why does it increment i by 6 and why does it check to see if n % (i+2) equals zero? Here is the JavaScript implementation. Explain to me like I'm five please. Thanks in advance.
function isPrime(n) {
    if (n <= 3) { return n > 1; }
    if (n % 2 == 0 || n % 3 == 0) { return false; }
    for (var  i = 5; i * i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0) { return false; }
    }
    return true;
}

 A: This checks to see if $n$ is a multiple of 2 or 3 (at the start) and then (main loop) whether $n$ is a multiple of 5,7,11,13,17,19,23,25,29,31 etc. $i$ is going up by 6 starting at 5, and it checks $i$ and $i+2$. So the only question is why every single prime is in that list? It's because every prime bigger than 3 must leave remainder 1 or 5 when you divide it by 6. So done.
A: Among $6n,6n+1,6n+2,6n+3,6n+4,6n+5$, the numbers $6n,6n+2,6n+3,6n+4$ are composite and there is no need to try them (as their own factors have already been tried before). Only $5+6n$ and $5+6n+2=6n'+1$ remain ($2$ out of $6$).

You can generalize, for instance with $30n+k$: only $30n+1,30n+7,30n+11,30+13,30+17,30n+19,30n+23,30n+29$ need to be tried ($8$ out of $30$).
A: As the other people answered it is merely a test to divide by all numbers of the form $6n+1$ and $6n+5$. The $+=6$ in the for loop makes the coefficient of $n$ be $6$. Starting at $5$, one can show that all prime numbers can be written in the form of $6n+1$ or $6n+5$. There are a lot of numbers that are in the form of 6n+1$ or $6n+5$, but all prime numbers can still be written in that form.
This is because prime numbers by definition cannot be written in the form of $6n, 6n+2, 6n+3, 6n+4$ (note that $6n+6$ can be written as $6n'$ so it cycles back)
The reason this is true is because $6n+2, 6n+4$ are even numbers and $6n+3$ is divisible by $3$.
