I got this code from codefights, and I am lack of terms to google it what this code actually does. What this function does is to get the sum of a prime number between 2 numbers which passed to parameter (a, b).
Here is the working code..
function Prime_sum(a, b){
for(s=0; b>=a; s += b--*!c)
for(c=b-1; b%c--; );
return s
}
And it pops me some questions like;
- What's the different between using 's=0' instead of 'var s = 0'?
- What does this s += b--*!c do? Shouldn't this throw an error since c was not declared?
- If you remove the last semi-colon on the 2nd loop, this will no longer function. Why is that?
- If you see 'b>=a' on first loop, in which part that makes 'b < a' that makes the loop ends?
Edit: Ignore my questions and explain me what this code actually does in order.
I'm sorry if the title isn't set properly as my question.