Suppose my code is as follows:
const days = ['Monday', 'Tuesday'];
for (const day of days) {
console.log(day);
}
It prints out 'Monday' and 'Tuesday'.
If for whatever reason, days is undefined, then I get a runtime error.
I could handle this by putting in code like the following:
if (undefined == days) {
// logic here
}
To me, that seems a little clunky. Is there a way to have the for ... of loop ignore undefined values? Basically, treat it like a zero-length array and so the logic inside the for loop won't execute, but it won't throw an error either.