公司的JS笔试题~你能的JS基础牢不牢!嘿嘿

代码
 1 var flag=true;
 2 var flag2=true;
 3 if(flag==true)
 4 {
 5   var i=0
 6   
 7   j=1
 8   
 9   if(flag2==true)
10   {     
11     for(  var m=0;m<10;m++)
12     {
13      
14      }
15   }
16 }
17 
18 alert(i);
19 alert(j);
20 alert(m);


// 输出 0, 1, 10

 

var x = 1

 
function ScopeTest(){
    alert( x );   
}
 
 ScopeTest(); 
// 输出 1


 // 输出 1

 

var x = 1

 
function ScopeTest(){
    alert( x );   
    
var x = 'hello world';
    alert( x );    
 }
 
 ScopeTest(); 


// 输出 underfined, hello world

 

var name = 'laruence';     
function echo()
 {         
  alert(name);   
 }      
function env()
 {
    
var name = 'eve';         
    echo();   
}      

env();


// 输出 laruence

 

function test(xxx){
  alert(xxx);
  
var xxx = 123
  
function xxx(){  
  }
  alert(xxx); 
}
test(
444);


// 输出 function xxx(){},123 

 

           function JSClass() {
            
this.m_Text = 'division element';
            
this.m_Element = document.createElement('DIV');
            
this.m_Element.innerHTML = this.m_Text;

            
this.m_Element.attachEvent('onclick'this.ToString);
        }

        JSClass.prototype.Render 
= function() {
            document.body.appendChild(
this.m_Element);
        }

        JSClass.prototype.ToString 
= function() {
            alert(
this.m_Text);
        };

        
var jc = new JSClass();
        jc.Render();
//添加渲染div元素
        jc.ToString(); //输出 division element

        
//click添加的div元素division element会输出underfined,为什么?

相关文章: