Santosh Viswanatham

Feb 13, 2021

2 min read

Log all Prime Numbers until `n` using Javascript Generators

Photo by Freddie marriage on Unsplash
function main() {
const primeNumberGenerator = getAllPrimeNumbers(23);
let primeNumber;
while ((primeNumber = primeNumberGenerator.next().value) !== undefined) {
console.log(primeNumber);
}
}