I have got this code from the StackOverflow but can someone explain me how does the sieve[i] evaluates to true or false?

Tell us what’s happening:
Describe your issue in detail here.

**Your code so far**

function sumPrimes(max) {
let sieve = [], i, j,total = 0,primes = [];
for (i = 2; i <= max; i++) {
   console.log(sieve[i]);
    if (!sieve[i]) {  
        // i has not been marked -- it is prime
        primes.push(i);
        for (j = i << 1; j <= max; j += i) {
            sieve[j] = true;
        }
    }
}
// console.log(primes);
primes.forEach(x=>total += x);
return total;
}

sumPrimes(10);
**Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36

Challenge: Sum All Primes

Link to the challenge:

sieve[i] starts at undefined, so !sieve[i] is true

after this !sieve[i] is false and is not touched again

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.