DEV Community

Discussion on: What The For Loop?

 
joelnet profile image
JavaScript Joel

extract isOdd out and you can now reuse it elsewhere. It also improves the readability of the for loop.

const isOdd = n => n % 2 === 1

for (let i=0; i<=20; i++){
  if (isOdd(i) {
    console.log(i)
  }
} 
Thread Thread
 
nektro profile image
Meghan (she/her)

isOdd should not need to be a function

Thread Thread
 
yechielk profile image
Yechiel Kalmenson