JS Complete (10) : Hoisting

yoneeki·2023년 1월 4일
0

JS_Complete

목록 보기
10/13

Hoisting

  • Execution has always 3 parts : A variable environemnt, scope chain, this keyword
  • 자바스크립트 엔진(인터프리터)이 코드를 실행하기 전에 변수와 함수, 클래스의 선언문을 끌어올리는 것을 말한다. 변수의 선언과 초기화를 분리한 후, 선언만 코드의 최상단으로 옮긴다.

Hoisting

  • It makes some types of variables accessible/usable in the code before they are actually declared. "Variables lifted to the top of their scope".
  • Behind the scenes : Before execution, code is scanned for variable declarations, and for each variable, a new property is created in the variable environment object.

    ** it only works in strict mode (highly recommended)

Temporal Dead Zone, Let and Const

Why Hoisting?

  • Using functions before actual declaration.
  • var hoisting is just a byproduct.

Why TDZ

  • Makes it easier to avoid and catch errors. accessing variables before declaration is bad practice and should be avoided.
  • Makes const variables actually works.
profile
Working Abroad ...

0개의 댓글