JS函数定义顺序

New*_*ger 1 javascript

非常快速的问题,因为我有一些奇怪的错误,我找不到任何关于此的文档.是否在文件中定义了哪些函数?

例如:

function a() {
  b(); //defined below the current function
}

function b() {
  //do something
}
Run Code Online (Sandbox Code Playgroud)

它被认为是正确的还是我必须记住订单?

mus*_*.0x 5

由于变量提升,"var语句和函数声明将被移动到其封闭范围的顶部"[1].

这有时会导致陷阱,但只要加载包含该函数的文件,顺序就无关紧要了.

[1] http://bonsaiden.github.io/JavaScript-Garden/#function.scopes,http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html