var
ES2015 이전 var로 변수를 선언
but ES2015부터 const와 let이 대체
가장 큰 차이점 : 블록 스코프 (var은 함수 스코프)
if(true){
var x = 3;
}
console.log(x); // 3
if(true){
const y = 3;
}
console.log(y); // Uncaught ReferenceError ReferenceError: y is not defined
기존 : 함수 스코프(function(){}이 스코프의 기준점)
var 는 함수 스코프를 존중
const는 블록 스코프를 존중
const
const a = 3;
a = "5";
console.log(a); // 에러
const b = { file : "hello world"};
b.file = "hi";
console.log(b); // { file : "hi" };
const c =; // 에러
let
let c = 3;
c = 5;
console.log(c); // 5
let d; // 가능