变量提升与函数提升

函数提升优先于变量提升 且不会被变量所覆盖  但是会被变量赋值覆盖

var b
	function b(){console.log("我是一个函数")}
	console.log(typeof b)   //function
	console.log(b())  //“我是一个函数”  ‘undefined’
	console.log("----------------")
	b = 4
	console.log(b)   //4
	console.log(b())  //b is not a function
 //面试题2
	if(!(z in window)){
	    var z = 1
	}
	console.log("z是多少---",z)  //undefined

	var c = 1
	function c(c){
	    console.log("c是多少---",c)
		var c = 3
	}
	c(2)   //c is not a function
发布了54 篇原创文章 · 获赞 8 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/yang295242361/article/details/101675508