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] 第63天 举例子说明javascript的变量声明提升和函数声明提升 #281
Labels
js
JavaScript
Comments
var getName = function(){
console.log(4)
}
function getName() {
console.log(5)
}
getName() // 4 函数声明优先级高于var声明, 故 4 覆盖了 5 |
变量声明
函数声明
变量声明只提升声明 不提升赋值操作,函数声明 函数体整体被提升。
提升之后变成:
|
不是4的优先级是高于5, 而是5的优先级高于4, |
先声明函数名,再声明 var 变量名,然后按顺序从上到下赋值。
|
|
console.log(a);//a会被提升到作用域最前面声明 var a = undefined
var a = 1; console.log(a);
var a = 1;
// 变量和函数都会被提升 函数优先
function a() {
} |
|
// 函数表达式 -- 匿名函数
|
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
第63天 举例子说明javascript的变量声明提升和函数声明提升
The text was updated successfully, but these errors were encountered: