一个JS题目反映出你的JS的掌握程度

先不讲文章的主题是什么,大家先来做做这些题目,看你能做对多少。这也是反映了你对JS基础知识的掌握程度!

 

代码
<script type="text/javascript">
        
function doTest(s) {
            document.writeln(s 
+ " : " + eval(s) + "<br />");
        }

        doTest(
"null==undefined");         //1:                                         
        doTest('null==""');             //2:                                         
        doTest('null==0');                 //3:                                         
        doTest('0==""');                 //4:                                         
        doTest('false==0');             //5:                                         
        doTest('false==""');             //6:                                         
        doTest('true==0');                 //7:                                         
        doTest('true==1');                 //8:                                         
        doTest('true==-1');             //9:                                         
        doTest('false==null');             //10:                                        
        doTest('');                     //11:                                        
        doTest('false==undefined');     //12:                                        
        doTest('-0===+0');                 //13:
        doTest('-0==+0');                 //14:                                        
        doTest('-(-0)===0');             //15:                                        
        doTest('false===(!true)');         //16:                                        
        doTest('typeof(null)');         //17:                                        
        doTest('typeof(false)');         //18:                                        
        doTest('typeof(undefined)');     //19:                                        
        doTest('typeof(1)');             //20:                                        
        doTest('typeof(+1.1)');         //21: 
 </script>                                       

 

怎么样?自己给自己打下分,总共22个题目,你对了多少个呢?

这些题目我也不知道应该去讲解,只是想让大家对自己做错的题目进行更深一步的思考、挖掘。

下面我们来公布答案吧:

 

代码
<script type="text/javascript">
        
function doTest(s) {
            document.writeln(s 
+ " : " + eval(s) + "<br />");
        }

        doTest(
"null==undefined");         //1:null==undefined : true                     
        doTest('null==""');             //2: null=="" : false                          
        doTest('null==0');                 //3: null==0 : false                           
        doTest('0==""');                 //4: 0=="" : true                             
        doTest('false==0');             //5:false==0 : true                            
        doTest('false==""');             //6: false=="" : true                          
        doTest('true==0');                 //7:true==0 : false                            
        doTest('true==1');                 //8:true==1 : true                             
        doTest('true==-1');             //9: true==-1 : false                          
        doTest('false==null');             //10:false==null : false                        
        doTest('');                     //11: : undefined                            
        doTest('false==undefined');     //12:false==undefined : false                   
        doTest('-0===+0');                 //13:-0===+0 : true                        
        doTest('-0==+0');                 //14:-0==+0 : true                             
        doTest('-(-0)===0');             //15:-(-0)===0 : true                           
        doTest('false===(!true)');         //16:false===(!true) : true                       
        doTest('typeof(null)');         //17:typeof(null) : object                        
        doTest('typeof(false)');         //18:typeof(false) : boolean                      
        doTest('typeof(undefined)');     //19:typeof(undefined) : undefined                
        doTest('typeof(1)');             //20:typeof(1) : number                         
        doTest('typeof(+1.1)');         //21:typeof(+1.1) : number                      
    </script>

 

 

 给大家留下一个问题:3||6&&9的运算结果是什么?

如果不知道答案可以看这里:&&和||运算

posted @ 2009-12-09 13:36  清茶  阅读(130)  评论(0编辑  收藏  举报