首页 > 编程语言 >JavaScript works behind the scenes —— hoisting and TDZ(变量提升和暂时性死区)

JavaScript works behind the scenes —— hoisting and TDZ(变量提升和暂时性死区)

时间:2022-10-27 01:00:14浏览次数:45  
标签:变量 JavaScript scenes hoisting TDZ behind 暂时性

JavaScript works behind the scenes —— hoisting and TDZ(变量提升和暂时性死区)

concept

Makes some types of variables accessible/usable in the code before they are actually declared. "Variables lifted to the top of their scope"

(让某些类型的变量可以在他们被真正声明之前就可以使用,将他们提升到最高层的作用域)

how to hoisting?

image-20221027004918334

TDZ(Temporal dead zone)(暂时性死区)

变量用let/const声明之前就调用,那时不可用,在声明之前的scope成为暂时性死区。

example:

console.log(`Hello ${name}`)
let name = 'kihyun'

throw error: Reference Error: Cannot access 'name' before initialization

标签:变量,JavaScript,scenes,hoisting,TDZ,behind,暂时性
From: https://www.cnblogs.com/kihyunBlog/p/16830681.html

相关文章