Hoisting

vancouver·2023년 8월 24일

Hoisting

모든 변수 선언문이 코드의 최상단으로 이동되는 것처럼 느껴지는 현상을 이야기한다.

var는 Hoisting을 막아주지 못함.

let, const는 Hoisting을 막아줄수 있음.

var name;
console.log(name)
name = `hello`
  • 정상적으로 출력됨.
let name;
console.log(name)
name=`hello`
  • undefined라고 정의됨.
const name;

conole.log(name)
name=`hello`
  • Hoisting 오류 출력.
    Uncaught SyntaxError: Missing initializer in const declaration(Hoisting 에러)

0개의 댓글