[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Errors/Invalid_for-of_initializer [Back]  [Original]

SyntaxError: a declaration in the head of a for-of loop can't have an initializer - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

SyntaxError: a declaration in the head of a for-of loop can't have an initializer

SyntaxError: a declaration in the head of a for-of loop can't have an initializer (Firefox)

SyntaxError: for-of loop variable declaration may not have an initializer. (Chrome)

SyntaxError

for...of |for (var i = 0 of iterable)| for-of for

for-of

js
let iterable = [10, 20, 30];

for (let value = 50 of iterable) {
  console.log(value);
}

// SyntaxError: a declaration in the head of a for-of loop can't
// have an initializer

for-of

(value = 50) for-of 50

js
let iterable = [10, 20, 30];

for (let value of iterable) {
  value += 50;
  console.log(value);
}
// 60
// 70
// 80


Web Proxy Viewer  |  New URL  |  Original Page