let 과 const
let은 재할당이 가능하다
Ex) let a = 1;
a=2; ⭕️
-const(상수)는 재할당이 불가능하다
Ex) const text = 'hello';
text = 'hi'; ❌
(프로그래밍을 할 때 let보다는 const를 선호하는 것이 좋다.)
-상수 변수의 이름은 항상 대문자로, 단어와 단어 사이에는 언더 스코어로 표기한다
Ex) const MAX_FRUITS = 5;
-재할당이 불가능한 상수
const apple = { name: 'apple', color: 'red', };
apple = { name: 'orrange', color: 'yellow', }; ❌
apple.name = 'orange' ⭕️
설명: apple이라는 변수 자체에 다른 객체를 재할당 할 수는 없지만
객체가 가리키는 곳의 있는 실제 객체 값은 변경할 수 있다.(재할당만 되지 않는다.)
let = 재할당(Reassignable)⭕️ 변경(Mutable)⭕️
const = 재할당(Reassignable)❌ 변경(Mutable)⭕️