为什么 for 循环的初始值设定项用方括号括起来?

Why is the initializer of for loop enclosed in square brackets?

for (let i=0; i<select.options.length; i++) {
    if(selectObject.options[i].selected) {
        numberSelected++
    }
}

在循环中访问初始化器需要加方括号吗?

是的,存在更清晰且不易出错的代码(就像您问的那样)。

const optionsIterator = select.options.values();

for (const oneOption of optionsIterator) {
    if(oneOption.selected) {
        numberSelected ++
    }
}