Notice
Recent Posts
Recent Comments
Link
투케이2K
384. (javaScript) [에러 정리] SyntaxError: for-in loop head declarations may not have initializers 에러 정리 본문
JavaScript
384. (javaScript) [에러 정리] SyntaxError: for-in loop head declarations may not have initializers 에러 정리
투케이2K 2025. 4. 9. 20:08728x90
[개발 환경 설정]
개발 툴 : Edit++
개발 언어 : JavaScript
[설명 정리]
-----------------------------------------------------------------------------------------
[사전 설명 및 설정 사항]
-----------------------------------------------------------------------------------------
- 개발 환경 : Web
- 개발 기술 : JavaScript (자바스크립트) / SyntaxError / for-in loop head declarations may not have initializers
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
[설명 정리]
-----------------------------------------------------------------------------------------
1. SyntaxError: for-in loop head declarations may not have initializers 에러는 for...in 반복문에서 잘못 된 구문 사용으로 인해 발생하는 에러입니다
2. SyntaxError: for-in loop head declarations may not have initializers 에러 발생 예시 :
const obj = { a: 1, b: 2, c: 3 };
for (const i = 0 in obj) { --------------> const i = 0 구문으로 인해서 에러 발생 (엄격 모드 / 비엄격 모드에서는 for (var i in obj) 처럼 동작 수행)
console.log(obj[i]);
}
3. SyntaxError: for-in loop head declarations may not have initializers 에러 예방 for...in 구문 :
"use strict";
var obj = { a: 1, b: 2, c: 3 };
for (var i in obj) {
console.log(obj[i]);
}
4. SyntaxError: for-in loop head declarations may not have initializers 에러 발생 시 for...in 반복문 사용 구문 점검이 필요하며,
엄격 모드 및 비엄격 모드 동작 수행도 확인이 필요 합니다.
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
[참고 사이트]
-----------------------------------------------------------------------------------------
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Errors/Invalid_for-in_initializer
-----------------------------------------------------------------------------------------
728x90
반응형
'JavaScript' 카테고리의 다른 글
Comments
