[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/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

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

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

  SyntaxError: for-of loop head declarations cannot have an initializer (Edge)
  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)

In this article

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

for-of (value = 50) . 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