The questions are as follows:
1 f = function() { return true; };2 g = function() { return false; }; 3 (function() {4 if (g() && [] == ![]) { 5 f = function f() { return false; }; 6 function g() { return true; }7 } 8 })();9 alert(f()); // true or false ?
What are the differences between IE6, IE7, and IE8 and other non-ie instances?
1 var f = function foo(){ 2 return typeof foo; // "foo" is available in this inner scope 3 }; // `foo` is never visible "outside" 4 typeof foo; // "undefined" 5 f(); // "function"
All browsers except IE6, 7, and 8 show that foo is undefined.
This is the JScript bugs. It seems that it has been fixed in ie9 beta2? (Not installed yet, to be confirmed)
There are two "Features" in IE"
1. The identifier in the function declaration can contain. operators, such as function window. onload (){}
2. The identifier in the function expression can be accessed outside the function. var F = function g () {}; typeof g; // "function"
Related Articles:
About JS engine pre-Analysis of VaR and Function
How to Understand named functions in expressions
Function declaration and function expression
Exploring the name function expressions
Named function expressions
After reading these materials, it should be easy to do this question?
In IE6, 7, and 8, the code is equivalent:
1 f = function() { return true; }; 2 g = function() { return false; }; 3 (function() { 4 var f, g; 5 g = function() {return true;} 6 f = function() {return false;} 7 if (g()) { 8 f = f; 9 }10 })();11 alert(f());
The code in FF is equivalent:
1 f = function() { return true; };2 g = function() { return false; };3 (function() {4 if (g()) {5 /**..*/6 }7 })();8 alert(f());
In Chrome, it is equivalent:
1 f = function() { return true; }; 2 g = function() { return false; }; 3 (function() { 4 var g; 5 function g() { 6 return true; 7 } 8 if (g()) { 9 f = function f() {10 return false;11 }12 }13 })();14 alert(f());