'const'로 선언된 변수에는 재할당(reassignment)이 금지되지만,
'const'로 선언된 배열과 객체의 경우 새로운 요소를 추가하거나 삭제할 수 있습니다.
하지만 여전히 재할당은 금지됩니다.
구글 스타일 가이드에서는
Declare all local variables with either const or let. 모든 지역 변수들을 const나 Let 으로 선언하세요.
Use const by default, unless a variable needs to be reassigned. The var keyword must not be used.
const를 default로 쓰세요. 재할당이 필요한 경우를 제외하고요. var 키워드는 절대 쓰지 마세요!! 라고 말하고 있다.
어딘가에서 본 기억으로는, 일단 const로 변수를 선언하는 버릇을 들이고, 재할당이 필요한 경우가 생기면 그때 const로 선언해놓았던 변수를 let으로 바꾸는 습관을 들이라고 했다....
아직은 let이 너무 편하지만, const를 사용하는 것에 버릇을 들여보자.....
참고 : https://google.github.io/styleguide/jsguide.html#features-use-const-and-let
Google JavaScript Style Guide
Google JavaScript Style Guide 1 Introduction This document serves as the complete definition of Google’s coding standards for source code in the JavaScript programming language. A JavaScript source file is described as being in Google Style if and only i
google.github.io
'자바스크립트 > 기초' 카테고리의 다른 글
함수 선언식과 함수 표현식의 차이 (1) | 2021.06.06 |
---|---|
화살표 함수 사용법 익히기 (0) | 2021.06.06 |
배열 arr.slice / arr.splice / arr.join 다시보기 (3) | 2021.06.05 |
Spread syntax/Rest parameter/Destructing (4) | 2021.06.01 |
객체, 배열 코딩앙마 유튜브 정리 (1) | 2021.05.29 |