Created
July 22, 2014 00:14
-
-
Save jikeytang/c95f42b08143a7972253 to your computer and use it in GitHub Desktop.
[ Javascript ] - 20140722-题目1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 感谢深圳[时空]贡献 腾讯面试题一枚 | |
f = function() {return true;}; | |
g = function() {return false;}; | |
(function() { | |
if (g() && [] == ![]) { | |
f = function f() {return false;}; | |
function g() {return true;} | |
} | |
})(); | |
console.log(f()); | |
// true or false ? 为什么? | |
ps: | |
考察点: | |
作用域链(scope chain)、执行环境(execution context)、变量对象(variable object)命名函数表达式 等。 |
in firefox: true ( because firefox don't hoist function declearation in blocks)
in chrome: false ( if中的函数声明是被提升了的)
if( g() && [] == ![] ) => if( (g()) && ( [] == ![]) ) //关系运算符优先级高于逻辑运算符 [] == ![] //true
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
false
∵变量声明会提前
∴自执行函数中实际运行顺序如下
由上可知,console.log(f()) 的值为false