var, let 둘 다 예약어가 아니던가? 왜 둘의 오류 메시지가 다를까.
Uncaught SyntaxError: var is disallowed as a lexically bound name
Uncaught SyntaxError: let is disallowed as a lexically bound name
es6가 나오기 전에 let은 완벽히 변수가 될 수 있었음.
-> 그래서 let만이 유일하게 예약어가 아니었던 적이 있어서 에러메시지가 다르다고 한다.
예를 들어) var let = 3의 경우에는 올바른 문법임.
let declarations didn't exist prior to the ES2015 standard, so let could be used freely as a variable name. Changing the language to stop allowing that variable name could have broken applications which were written before ES2015 existed, at a time when let was a perfectly good variable name. (Which covered a period of twenty years -- 1995 to 2015!)
Since let was a new feature, there was no existing code to break, and disallowing let as a variable name avoided a potential source of syntactic confusion.
출처: https://stackoverflow.com/questions/50789375/var-let-is-ok-but-let-let-isnt/50789417
궁금해서 제로초님에게도 물어봐서 확인 완료.
[JS] Shorthand property names (0) | 2022.01.06 |
---|---|
[JS] 자바스크립트 실행 순서 (feat. 이벤트루프) (0) | 2021.12.02 |
[JS-ES6] 매개변수(rest), 전개 문법(spread) (0) | 2021.11.29 |
[Python] 'int' object is not callable (0) | 2021.11.09 |
[Python] 문제 풀면서 개념 다시 잡은 것들 (계속 업데이트 ing) (0) | 2021.11.09 |