What leads to 'uncaught typeerror: x is not iterable' in javascript?

This error arises when attempting to iterate over something that isn't iterable, like an undefined variable or a number.

Example:


let notIterable;
for (let item of notIterable) {
    console.log(item);
}

Solution:


let iterable = ['a', 'b', 'c'];
for (let item of iterable) {
    console.log(item);
}
Ensure that the object you're trying to iterate over is iterable, like an array or a string.

Beginner's Guide to JavaScript