Skip to content

Instantly share code, notes, and snippets.

@tvytlx
Last active April 19, 2017 09:47
Show Gist options
  • Save tvytlx/25d608bafd4d987c58cac93ca895b614 to your computer and use it in GitHub Desktop.
Save tvytlx/25d608bafd4d987c58cac93ca895b614 to your computer and use it in GitHub Desktop.
ES6 TDZ
规范里用来声明 var/let 变量的内部方法是 CreateMutableBinding(),初始化变量用 InitializeBinding(),为变量赋值用 SetMutableBinding(),
引用一个变量用 GetBindingValue()。在执行完 CreateMutableBinding() 后没有执行 InitializeBinding() 就执行 SetMutableBinding() 或者
GetBindingValue() 是会报错的,这种表现有个专门的术语(非规范术语)叫 TDZ(Temporal Dead Zone)。
标准说用let和const初始化失败的变量将会永久的不能初始化了。
let/const v = xx // xx is not defined
let/const v = 1 // v has already been declared
v = 1; let c = v // v is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment