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

[js] 第112天 函数声明与函数表达式有什么区别? #1031

Open
haizhilin2013 opened this issue Aug 5, 2019 · 5 comments
Open
Labels
js JavaScript

Comments

@haizhilin2013
Copy link
Collaborator

第112天 函数声明与函数表达式有什么区别?

@haizhilin2013 haizhilin2013 added the js JavaScript label Aug 5, 2019
@Clearives
Copy link

函数声明会函数提升,将函数声明提升到作用域最上层,而函数表达式必须赋值完成了才能调用。

@EragonBubble
Copy link

函数声明

function fn() {
///...
}

函数表达式

const aa = function() {
///...
}

区别:
1.函数声明,函数名必须有,在函数表达式中可以省略函数名
2.函数声明会被预解析,函数表达式不会

@AnsonZnl
Copy link
Contributor

AnsonZnl commented Aug 6, 2019

最大的区别就是函数声明会提升至作用域的顶端,函数表达式则会在赋值之后能调用。

@nowherebutup
Copy link

  • 函数声明: 声明+赋值
  • 函数表达式: 声明,代码执行到此处才会赋值,所以在此之前,函数不能被调用

@xiaoqiangz
Copy link

函数声明: 作用域会提升
function fn() {}
函数表达式:只有代码执行到该处后,函数才能被调用
var fn = function() {}

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

No branches or pull requests

6 participants