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

第1题(2019-07-22) 以下代码会输出什么 #17

Open
qappleh opened this issue Aug 19, 2019 · 1 comment
Open

第1题(2019-07-22) 以下代码会输出什么 #17

qappleh opened this issue Aug 19, 2019 · 1 comment
Labels

Comments

@qappleh
Copy link
Owner

qappleh commented Aug 19, 2019

function fn(a) {
	console.log(a);
	var a = 2;
	function a() {}
	console.log(a);
}
fn(1);  
@qappleh
Copy link
Owner Author

qappleh commented Aug 19, 2019

答案:f a() { } 2
解析:我们知道预解析阶段,变量声明和函数声明会提前,且变量名和函数名同名时,函数优先级高于变量,会覆盖变量,因此第一个输出的是f a(){ },继续执行,会执行a=2,再输出的时候就会输出2,不理解的同学百度一下变量提升和函数提升

@qappleh qappleh added the js label Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant