1. A bloody case caused by front-end questions about JS Functions

Source: Internet
Author: User

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()); 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.