JavaScript专业八级测试,你能做对几道?

注* 本文翻译自 JavaScript Puzzlers! do you really know JavaScript?  (JavaScript迷题!你真的懂JavaScript吗?) 。本文考察了很多JavaScript中生僻冷门用法和许多容易忽视混淆的概念,据多名Hacker News网友回复,做第二遍依然无法全部答对,jser专家们可以尝试一下。 


  1. ["1", "2", "3"].map(parseInt)
  2. [typeof null, null instanceof Object]
  3. [ [3,2,1].reduce(Math.pow), [].reduce(Math.pow)] ]
  4.       var val = 'smtg';
          console.log('Value is ' + (val === 'smtg') ? 'Something' : 'Nothing');
        
  5.     var name = 'World!';
        (function () {
          if (typeof name === 'undefined') {
            var name = 'Jack';
            console.log('Goodbye ' + name);
          } else {
            console.log('Hello ' + name);
          }
        })();
        
  6.     var END = Math.pow(2, 53);
        var START = END - 100;
        var count = 0;
        for (var i = START; i <= END; i++) {
          count++;
        }
        console.log(count);
        
  7.     var ary = [0,1,2];
        ary[10] = 10;
        ary.filter(function(x) { return x === undefined;});
        
  8.     var two   = 0.2
        var one   = 0.1
        var eight = 0.8
        var six   = 0.6
        [two - one == one, eight - six == two]
        
  9.     function showCase(value) {
          switch(value) {
            case 'A':
              console.log('Case A');
              break;
            case 'B':
              console.log('Case B');
              break;
            case undefined:
              console.log('undefined');
              break;
            default:
              console.log('Do not know!');
          }
        }
        showCase(new String('A'));
        
  10.     function showCase2(value) {
          switch(value) {
          case 'A':
            console.log('Case A');
            break;
          case 'B':
            console.log('Case B');
            break;
          case undefined:
            console.log('undefined');
            break;
          default:
            console.log('Do not know!');
          }
        }
        showCase(String('A'));
        
  11.     function isOdd(num) {
          return num % 2 == 1;
        }
        function isEven(num) {
          return num % 2 == 0;
        }
        function isSane(num) {
          return isEven(num) || isOdd(num);
        }
        var values = [7, 4, '13', -9, Infinity];
        values.map(isSane);
        
  12.     parseInt(3, 8)
        parseInt(3, 2)
        parseInt(3, 0)
        
  13. Array.isArray( Array.prototype )
  14.     var a = [0];
        if ([0]) { 
          console.log(a == true);
        } else { 
          console.log("wut");
        }
        
  15. []==[]
  16.     '5' + 3  
        '5' - 3
        
  17. 1 + - + + + - + 1 
  18.     var ary = Array(3);
        ary[0]=2
        ary.map(function(elem) { return '1'; });
        
  19.     function sidEffecting(ary) { 
          ary[0] = ary[2];
        }
        function bar(a,b,c) { 
          c = 10
          sidEffecting(arguments);
          return a + b + c;
        }
        bar(1,1,1)
        
  20.     var a = 111111111111111110000,
        b = 1111;
        a + b;
        
  21. Number.MIN_VALUE > 0
  22. [1 < 2 < 3, 3 < 2 < 1]
  23.     2 == [[[2]]]
        
  24.     3.toString()
        3..toString()
        3...toString()
        
  25.     (function(){
          var x = y = 1;
        })();
        console.log(y);
        console.log(x);
        
  26.     var a = /123/, b = /123/;
        a == b
        a === b
        
  27.     var a = [1, 2, 3],
            b = [1, 2, 3],
            c = [1, 2, 4]
        a ==  b
        a === b
        a > c
        a < c
        
  28.     var a = {}, b = Object.prototype;
        [a.prototype === b, Object.getPrototypeOf(a) === b]
        
  29.     function f() {}
        var a = f.prototype, b = Object.getPrototypeOf(f);
        a === b
        
  30.     function foo() { }
        var oldName = foo.name;
        foo.name = "bar";
        [oldName, foo.name]
        
  31. "1 2 3".replace(/\d/g, parseInt)
  32.     function f() {}
        var parent = Object.getPrototypeOf(f);
        f.name // ?
        parent.name // ?
        typeof eval(f.name) // ?
        typeof eval(parent.name) //  ?
        
  33.     var lowerCaseOnly =  /^[a-z]+$/;
        [lowerCaseOnly.test(null), lowerCaseOnly.test()]
        
  34. [,,,].join(", ")
  35.     var a = {class: "Animal", name: 'Fido'};
        a.class
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值