In both Firefox and Chrome, I tested the code snippet below:
function test() {
console.log("***")
return [1,2,3]
}
for (const t of test()) {
console.log(t)
}
After running this code, I noticed that the test
function was only called once. This got me thinking - is this the standard behavior for this type of loop? Could it be similar to the initialization part of a regular
for ([initialization]; [condition]; [final-expression])
loop? To my surprise, neither the MDN documentation nor the ECMA standard provided clear explanations on this topic.