Control flow statements 23 Flashcards
1
Q
What are the two operators for controlling loops while we are inside of them?
A
break and continue
break: exits the loop, like a return statement
continue: skips an iteration of the loop
2
Q
How to loop over an async iterable in ES6+?
A
for-await-of loop
3
Q
Why should you avoid for-in loop ES1?
A
its a bad choice for looping through arrays
- it visits all enumerable property keys (owned and inherited)
const arr = [1,2,3]
arr.prop = ‘prop value’
for (const key in arr) {
console.log(key)
}
// 0
// 1
// 2
// 3
// prop
safe if you’re using on objects i guess?