I accidentally witnessed that this causes an error in V8 (Chrome, Node.js, etc):
for (let val of Symbol()) { /*...*/ }
TypeError: Symbol is not a function or its return value is not iterable
It appears that any other non-iterable value (including a function) causes another error:
for (let val of function () { throw 'never called' }) { /*...*/ }
TypeError: (intermediate value) is not iterable
As the reference states, the error is specific to Chrome:
TypeError: 'x' is not a function or its return value is not iterable (Chrome)
...
The value which is given as the right hand-side of for…of or as argument of a function such as Promise.all or TypedArray.from, is not an iterable object. An iterable can be a built-in iterable type such as Array, String or Map, a generator result, or an object implementing the iterable protocol.
It seems that none of listed things are expected to accept a function instead of iterable as an argument so it's unclear why the error puts emphasis on function type.
Is there any meaning to this error? Are there circumstances under which is not a function
remark makes sense in its context?
for (let val of (function () {})()) { }
- you're not calling the function in your example. – Sluicefor (let val of Number(1)) {}
andfor (let val of Boolean(true)) {}
emit the same error.for (let val of 1) {}
andfor (let val of true) {}
do not. – Boy[...Symbol()]
will throw the same TypeError, moving here to delete my answer and continue discussion – Placate