var name = 'Jenna';
function newFunction( ) {
var newName = 'Lisa';
}
console.log(newName); // error: newName is not defined
1) var은 지역변수와 전역변수로 선언될 수 있다.
2) var은 재선언과 재할당이 가능하다.
3) 호이스팅(Hoisting): 코드 실행 전 함수 선언과 변수 선언을 최상단으로 끌어올리는 것이다.
1) let is block{} scoped.
2) let 는 재선언 될 수 없지만 재할당은 가능하다.
let name ='Jenna';
let name = ' Lisa'; // error: Identifier 'name' has already been declared.
let name = 'Jenna';
name = 'Lisa';
하지만 같은 변수가 다른 scope에 선언된다면 error가 나타나지 않는다
3) Hositing: let is not initailized as undefined like var.
1) const declarations are block scoped.
2) const cannot be updated or re-clared. 재선언이나 재할당이 불가하다.
const name = 'Jenna';
name = 'Lisa instead'// error: Assignment to constant variable.
const name ='Jenna';
const name = 'Lis instead' // error: identifier 'name' has already been declared
3) Hoisting: Just like let, const declarations are hoisted to the top but are not initialized.
loops