1,js中关于函数提升(在ES5中)
function f(){console.log(‘I am outside!‘)} ???(function(){ ???????if(false){// ???????????重复声明一次函数 ??????当然 ?在严格模式下是不允许在if,循环代码块中声明函数的 ???????????function f(){console.log("I am inside!")} ???????} ???????f(); ???})(); ???//结果为I am inside! ?????因为在ES5中存在变量 ?函数提升,重复声明,后面的覆盖前面的,所以最终函数是function f(){console.log("I am inside!")}
在ES6中用let声明就会产生块级作用域,不用立即执行匿名函数了
2.
alert(a)a();var a=3;function a(){ ???alert(10)} ??alert(a)a=6;a(); ?------------分割线------------------alert(a)a();var a=3;var a=function(){ ???alert(10)} ??alert(a)a=6;a(); 链接:https://juejin.im/post/5a0c170c6fb9a0451c39eff2
js中一些有趣的现象
原文地址:http://www.cnblogs.com/sundjly/p/7899296.html