mardi 22 janvier 2019

Javascript: Nicest way to catch a for loop over an undefined/null iterator?

Consider the next example. Is there a shorter version which does not require this if-statement?

let d = null  
if (d) { 
  for ( const z of d ) { 
   //
  } 
} 

For example, is something possible like:

let d = null  
for ( d && const z of d ) { 
 //
} 

Aucun commentaire:

Enregistrer un commentaire