`

考考你们的JS 我只作对了一半 你们试试

阅读更多
alert(typeof(NaN)); 

alert(typeof(Infinity));

alert(typeof(null)); 

alert(typeof(undefined)); 

alert(NaN==NaN); 

alert(NaN!=NaN); 

alert(NaN>NaN);  

alert(null==undefined);  

alert(null>=undefined);  

alert(null<=undefined);  

alert(null==null);

alert(null!=null); 

alert(null!=NaN); 

alert(null==NaN);

alert(NaN==undefined); 

alert(parseInt("123abc"));

alert("123abc"-0); 

alert(Infinity>10); 

alert(Infinity>"abc"); 

alert(Infinity==NaN);

alert(true==1); 

alert(new String("abc")=="abc"); 

alert(new String("abc")==="abc"); 

 
function step(a){

   return function(x){

      return x+a++;

   }

}

var a = step(10);

var b = step(20);

alert(a(10));

alert(b(20));

var a="123abc";

alert(typeof(a++));

alert(a);

 

 

用这个面试 估计死掉一大批啊

 

更新下新的 我错了8题

    1.


      (function(){
        return typeof arguments;
      })();

        “object”
        “array”
        “arguments”
        “undefined”
    2.


      var f = function g(){ return 23; };
      typeof g();

        “number”
        “undefined”
        “function”
        Error
    3.


      (function(x){
        delete x;
        return x;
      })(1);

        1
        null
        undefined
        Error
    4.


      var y = 1, x = y = typeof x;
      x;

        1
        “number”
        undefined
        “undefined”
    5.


      (function f(f){
        return typeof f();
      })(function(){ return 1; });

        “number”
        “undefined”
        “function”
        Error
    6.


      var foo = {
        bar: function() { return this.baz; },
        baz: 1
      };
      (function(){
        return typeof arguments[0]();
      })(foo.bar);

        “undefined”
        “object”
        “number”
        “function”
    7.


      var foo = {
        bar: function(){ return this.baz; },
        baz: 1
      }
      typeof (f = foo.bar)();

        “undefined”
        “object”
        “number”
        “function”
    8.


      var f = (function f(){ return "1"; }, function g(){ return 2; })();
      typeof f;

        “string”
        “number”
        “function”
        “undefined”
    9.


      var x = 1;
      if (function f(){}) {
        x += typeof f;
      }
      x;

        1
        “1function”
        “1undefined”
        NaN
    10.


      var x = [typeof x, typeof y][1];
      typeof typeof x;

        “number”
        “string”
        “undefined”
        “object”
    11.


      (function(foo){
        return typeof foo.bar;
      })({ foo: { bar: 1 } });

        “undefined”
        “object”
        “number”
        Error
    12.


      (function f(){
        function f(){ return 1; }
        return f();
        function f(){ return 2; }
      })();

        1
        2
        Error (e.g. “Too much recursion”)
        undefined
    13.


      function f(){ return f; }
      new f() instanceof f;

        true
        false
    14.


      with (function(x, undefined){}) length;

        1
        2
        undefined
        Error

 

分享到:
评论
42 楼 EePoo 2011-06-02  
这么全啊,以后肯定用得上
41 楼 ccyingfu 2011-05-19  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">




</HEAD>

<BODY>

</BODY>
</HTML>
<!--[if ie]>
   <script>
       var console = {};
	   console.log = function(text){
	       document.body.innerHTML += text+"<br/>";
	   }
   </script>
<![endif]-->

<script>
   console.log("typeof(NaN):   "+typeof(NaN));   
     
   console.log("typeof(Infinity):   "+typeof(Infinity));  
     
   console.log("typeof(null):   "+typeof(null));   
     
   console.log("typeof(undefined):   "+typeof(undefined));   
     
   console.log("(NaN==NaN):   "+(NaN==NaN));   
     
   console.log("(NaN!=NaN):   "+(NaN!=NaN));   
     
   console.log("(NaN>NaN):   "+(NaN>NaN));    
     
   console.log("(null==undefined):   "+(null==undefined));    
     
   console.log("(null>=undefined):   "+(null>=undefined));    
     
   console.log("(null<=undefined):   "+(null<=undefined));    
     
   console.log("null==null:   "+(null==null));  
     
   console.log("(null!=null):   "+(null!=null));   
     
   console.log("(null!=NaN):   "+(null!=NaN));   
     
   console.log("(null==NaN):   "+(null==NaN));  
     
   console.log("(NaN==undefined):   "+(NaN==undefined));   
     
   console.log("(parseInt(\"123abc\")):   "+(parseInt("123abc")));  
     
   console.log("(\"123abc\"-0):   "+("123abc"-0));   
     
   console.log("Infinity>10:   "+(Infinity>10));   
     
   console.log("Infinity>\"abc\":   "+(Infinity>"abc"));   
     
  console.log("(Infinity==NaN):   "+(Infinity==NaN));  
     
  console.log("(true==1):   "+(true==1));   
     
   console.log("(new String(\"abc\")==\"abc\"):   "+(new String("abc")=="abc"));   
     
  console.log("new String(\"abc\")===\"abc\":   "+(new String("abc")==="abc"));   
     
     
   function step(a){  
    
      return function(x){  
     
         return x+a++;  
     
      }  
    
   }  
     
   var a = step(10);  
     
   var b = step(20);  

  console.log(" function step(a){  ");
    
  console.log("    return function(x){  ");
     
  console.log("       return x+a++;  ");
     
  console.log("    }  ");
  console.log(" }  ");  
  console.log("var a = step(10); ");  
  console.log("var b = step(20);");   
    
     
     
     
   console.log("a(10):   "+a(10));  
     
   console.log("b(20):   "+b(20));  
     
   var a="123abc"; 
   
   console.log("var a=\"123abc\";"); 
        
   console.log("typeof(a++):   "+typeof(a++));  
    
  console.log("a:   "+a);  
</script>
40 楼 llongfeng 2011-05-17  
学习了……
39 楼 vb2005xu 2011-05-16  
上次去 校内面试 就 考了里面的几个 ... 面试的时候有点帮助吧
38 楼 guilipan 2011-05-15  
这个东西考的更多的是对ECMAScript的记忆程度。。。有些题目就是ECMASCRIPT里面规定的,没有为什么之说,因为就是这么规定的。。。
37 楼 mycybyb 2011-05-12  
错了3、4个
36 楼 ei0 2011-05-12  
这东西用到时,一测就知道了。这样的公司不去也罢,
35 楼 dwangel 2011-02-16  
刚看到这个帖子,投了良好。
万丈高楼平地起,没有平地就没有高楼。
基础很重要,前面一位说的很对,找bug时很有用。
有些新人,常常出莫名其妙的bug,就因为基础不扎实犯的小错。
被指出来,就说,哦没记住,要么就说,这谁会在意啊。
34 楼 crppwrc 2011-02-15  
难道要回复才能看到答案?
话说我是来看答案的。。。
JS快忘完了
33 楼 pouyang 2011-02-15  
该帖要被隐藏了,哈哈,我也正因为发了一个帖子,
被隐藏了,扣了 30分,真悲剧啊
http://www.iteye.com/topic/906025
32 楼 charrys 2011-02-15  
运行一遍不就全出来了吗!
31 楼 xql80329 2011-02-14  
能对一半 ,惭愧。
30 楼 adamed 2011-02-14  
vb2005xu 写道
投隐藏贴的 诸位 难道都是 大大么???? 或许是 无聊呢?

个人感觉 这些面试T是从很全的方面考的

里面 考了 对 js 的基础知识 , 细节知识 , 闭包 , 面向对象 , 类型转换 等诸多方面 ...

我敢这么说 可能你确实会做了 但是 不一定都能够 解释 为什么吧 , 比如

# alert((null==undefined) );  //true 
#  
# alert((null>=undefined));  //false 
#  
# alert((null<=undefined) );  //false

# alert((NaN==NaN) ); // false


alert((null==undefined) );
14. If x is null and y is undefined, return true.
15. If x is undefined and y is null, return true.

alert((NaN==NaN) ); // false

5. If x is NaN, return false.
6. If y is NaN, return false.
29 楼 telyy123 2011-02-14  
LifeFree 写道
作为试题而言一个不好的方面是考核内容太狭窄,也没有区分度。
一个几乎完全不知道javascript的小白,就瞎猜 true和false也差不多能对一半。
只有javascript的高级熟练工才能几乎全对。
像我这样的小白根据其他编程语言特性还可以从语义上多猜对几道题。


如果是我问,不仅要你的答案,而且要你的理由
28 楼 telyy123 2011-02-14  
achun 写道
基本考试都是考的记忆力,悲

这些可不是什么记忆力,没有足够的细心与平时的基础积累,这些是不好做好的
27 楼 adamed 2011-02-14  
我觉得这个东西还是应该先参考规范:
The comparison x == y, where x and y are values, produces true or false. Such a comparison is
performed as follows:
1. If Type(x) is different from Type(y), go to step 14.
2. If Type(x) is Undefined, return true.
3. If Type(x) is Null, return true.
4. If Type(x) is not Number, go to step 11.
5. If x is NaN, return false.
6. If y is NaN, return false.
7. If x is the same number value as y, return true.
8. If x is +0 and y is −0, return true.
9. If x is −0 and y is +0, return true.
10. Return false.
11.If Type(x) is String, then return true if x and y are exactly the same sequence of characters (same
length and same characters in corresponding positions). Otherwise, return false.
12. If Type(x) is Boolean, return true if x and y are both true or both false. Otherwise, return false.
13.Return true if x and y refer to the same object or if they refer to objects joined to each other (see
13.1.2). Otherwise, return false.
14. If x is null and y is undefined, return true.
15. If x is undefined and y is null, return true.
16.If Type(x) is Number and Type(y) is String,
return the result of the comparison x == ToNumber(y).
17.If Type(x) is String and Type(y) is Number,
return the result of the comparison ToNumber(x) == y.
18. If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
19. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).
20.If Type(x) is either String or Number and Type(y) is Object,
return the result of the comparison x == ToPrimitive(y).
21.If Type(x) is Object and Type(y) is either String or Number,
return the result of the comparison ToPrimitive(x) == y.
22. Return false.
NOTE
Given the above definition of equality:
String comparison can be forced by:"" + a == "" + b.
Numeric comparison can be forced by: a - 0 == b - 0.
Boolean comparison can be forced by: !a == !b.
The equality operators maintain the following invariants:
A != B is equivalent to !(A == B).
A == B is equivalent to B == A, except in the order of evaluation of A and B.
The equality operator is not always transitive. For example, there might be two distinct String objects,
each representing the same string value; each String object would be considered equal to the string
value by the == operator, but the two String objects would not be equal to each other.
Comparison of strings uses a simple equality test on sequences of code point value values. There is no
attempt to use the more complex, semantically oriented definitions of character or string equality and
collating order defined in the Unicode 2.0 specification. Therefore strings that are canonically equal
according to the Unicode standard could test as unequal. In effect this algorithm assumes that both
strings are already in normalised form.

看完规范就比较好理解啦
26 楼 achun 2011-02-13  
基本考试都是考的记忆力,悲
25 楼 tom33 2011-02-13  
拿这些题当面试题是不理智的。
24 楼 goddkiller 2011-02-12  
考察面太小。。马马虎虎,错了几道
23 楼 dir_murong 2011-02-12  
能把这个作对的都是大牛  反正我错了好多

相关推荐

Global site tag (gtag.js) - Google Analytics