Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

变量提升 #5

Open
upgrace opened this issue Apr 28, 2020 · 0 comments
Open

变量提升 #5

upgrace opened this issue Apr 28, 2020 · 0 comments

Comments

@upgrace
Copy link
Owner

upgrace commented Apr 28, 2020

  1. 定义-- what
    引擎会在解释JavaScript代码之前首先对齐进行编译,编译过程中的一部分工作就是找到所有的声明,并用合适的作用域将他们关联起来,这也正是词法作用域的核心内容

  2. 具体操作 -- how
    变量提升包括: 变量提升,函数提升, 函数字面量提升
    变量提升:将变量的定义提升到父作用域的顶部,默认等于undefined
    函数提升:将变量的定义整体提升,包括赋值
    函数字面量提升: 与变量提升相同

    https://www.cnblogs.com/pqjwyn/p/5365532.html
    
    ES6 中let const 不存在变量提升的问题, 并且产生了块级作用域。在块级作用域中,变量在声明之前的区域被称为暂时性死区。任何在暂 时性死区内访问变量的企图都会导致“运行时”错误(runtime error)。只有执行到变量的声明 语句时,该变量才会从暂时性死区内被移除并可以安全使用。
    
  3. 优先级 -- extend
    【进阶1-1期】理解JavaScript 中的执行上下文和执行栈 yygmind/blog#12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant