JavaScript TypeError: is not iterable
A plain-words explanation of this JavaScript message: what it means, the usual causes, and the steps that fix it.
The messageUncaught TypeError: getPair is not a function or its return value is not iterable
Make the error yourself
Run in Google Chrome 157.0.8103.51. This is the smallest example we could find that shows it.
JavaScript (in a script tag)
function getPair() {
console.log("loading");
}
const [first, second] = getPair();Browser console (the real message)
TypeError: getPair is not a function or its return value is not iterableWhy it happens
Array destructuring (const [a, b] = x), the spread operator ([...x]), for (const i of x) and new Set(x) all need an iterable, such as an array or a string. Here the function returned nothing, which means undefined, and undefined is not iterable. Chrome words this case as "getPair is not a function or its return value is not iterable". When the value is a plain variable, the message is shorter: "undefined is not iterable (cannot read property Symbol(Symbol.iterator))" or "data is not iterable". In React the same message appears when useState or a custom hook returns something other than an array.
How to fix it
- Log the value on the right of
=and see what it is. - Make the function return an array (
return [a, b]), or give a default:const [a, b] = getPair() ?? []. - If the data comes from a request, wait until it has arrived or start with an empty array.
- Do not mix up
[a, b](arrays) with{a, b}(objects) when you destructure.
The corrected version
JavaScript (in a script tag)
function getPair() {
return ["a", "b"];
}
const [first, second] = getPair();
console.log(first, second);Browser console (the corrected version)
a bHow to avoid it
Give functions a clear return type and use defaults for values that may be missing.
Questions
What is the difference between "x is not iterable" and "x is not a function"?
The first concerns looping and spreading; the second concerns calling something with brackets.
This is an independent guide. It is not connected with Python, Microsoft, Google, GitHub or the Git project. Product names belong to their owners. Examples were run on 13 November 2026 in a practice folder or a blank workbook; your version may word a message slightly differently.