一道面试题之Js中的函数声明提升

77 阅读1分钟
    function test(){
			console.log(1)
		}

		function init(){ 
			if (false) {
				function test(){
					console.log(2)
				}
			};

			test()
		};

		init(); // test is not a function

注解: (谷歌) test is not a function 逻辑代码会阻止函数体提示, 但是函数声明还是可以提升的~ 相当于声明 var test; 同理~ (低版本ie) 2 (某版本火狐) 1

	  if (false) {
        var a = 1;
    }
    
    console.log(a); // undefiend