Skip to content

函数提升、变量提升 #34

@yongheng2016

Description

@yongheng2016

函数名称解析顺序:

在JavaScript中,一个作用域(scope)中的名称(name)有以下四种:

  1. 语言自身定义(Language-defined): 所有的作用域默认都会包含this和arguments。

  2. 函数形参(Formal parameters): 函数有名字的形参会进入到函数体的作用域中。

  3. 函数声明(Function decalrations): 通过function foo() {}的形式。

  4. 变量声明(Variable declarations): 通过var foo;的形式。

https://dancon.gitbooks.io/git-books/content/js/essay/function_hoisting.html

http://www.cnblogs.com/betarabbit/archive/2012/01/28/2330446.html

http://www.jianshu.com/p/28ede2f4f30f

image


先提升作用域的变量声明,再看代码,所以条件语句中的变量不管怎样都会提升

image

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions