JavaScript|

JavaScript Puzzlers

基于ECMA 262(5.1)在浏览器环境中行为的JavaScript测验
0/ 0 of  44
  1. 1.这个表达的结果是什么? ["1", "2", "3"].map(parseInt)
    ["1", "2", "3"] [1, 2, 3] [0, 1, 2] other
  2. 2.以下表达式的运行结果是? [typeof null, null instanceof Object]
    ["object", false] [null, false] ["object", true] other
  3. 3.以下表达式的运行结果是? [ [3,2,1].reduce(Math.pow), [].reduce(Math.pow) ]
    an error [9, 0] [9, NaN] [9, undefined]
  4. 4.以下表达式的运行结果是? var val = 'smtg'; console.log('Value is ' + (val === 'smtg') ? 'Something' : 'Nothing');
    Value is Something Value is Nothing NaN other
  5. 5.以下表达式的运行结果是? var name = 'World!'; (function () { if (typeof name === 'undefined') { var name = 'Jack'; console.log('Goodbye ' + name); } else { console.log('Hello ' + name); } })();
    Goodbye Jack Hello Jack Hello undefined Hello World
  6. 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);
    0 100 101 other
  7. 7.以下表达式的运行结果是? var ary = [0,1,2]; ary[10] = 10; ary.filter(function(x) { return x === undefined;});
    [undefined × 7] [0, 1, 2, 10] [] [undefined]
  8. 8.以下表达式的运行结果是? var two = 0.2; var one = 0.1; var eight = 0.8; var six = 0.6; [two - one == one, eight - six == two]
    [true, true] [false, false] [true, false] other
  9. 9.以下表达式的运行结果是? function showCase(value){ switch(value){ case 'A': console.info('Case A'); break; case 'B': console.info('Case B'); break; case undefined : console.info('undefined'); break; default: console.info('Do not know!'); break; } } showCase(new String('A'));
    Case A Case B Do not know! undefined
  10. 10.以下表达式的运行结果是? function showCase(value){ switch(value){ case 'A': console.info('Case A'); break; case 'B': console.info('Case B'); break; case undefined : console.info('undefined'); break; default: console.info('Do not know!'); break; } } showCase(String('A'));
    Case A Case B Do not know! undefined
  11. 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);
    [true, true, true, true, true] [true, true, true, true, false] [true, true, true, false, false] [true, true, false, false, false]
  12. 12.以下三个表达式的运行结果是? parseInt(3, 8) parseInt(3, 2) parseInt(3, 0)
    3, 3, 3 3, 3, NaN 3, NaN, NaN other
  13. 13.以下表达式的运行结果是? Array.isArray( Array.prototype )
    true false error other
  14. 14.以下表达式的运行结果是? var a = [0]; if([0]) { console.info(a == true); } else { console.info("false"); }
    true false "false" other
  15. 15.以下表达式的运行结果是? []==[]
    true false error other
  16. 16.以下两个表达式的运行结果是? '5' + 3 ; '5' - 3
    "53", 2 8, 2 error other
  17. 17.以下表达式的运行结果是? 1 + - + + + - + 1
    2 1 error other
  18. 18.以下表达式的运行结果是? var arr = Array(3); arr[0] = 2 arr.map(function(elem){return '1';});
    [2, 1, 1] ["1", "1", "1"] [2, "1", "1"] other
  19. 19.以下表达式的运行结果是? function sidEffecting(arr){ arr[0] = arr[2]; } function bar(a, b, c){ c = 10; sidEffecting(arguments); return a + b + c; } bar(1, 1, 1);
    3 12 error other
  20. 20.以下表达式的运行结果是? var a = 111111111111111110000; b = 1111; console.info(a + b);
    111111111111111111111 111111111111111110000 NaN Infinity
  21. 21.以下表达式的运行结果是? var x = [].reverse; x();
    [] undefined error window
  22. 22.以下表达式的运行结果是? Number.MIN_VALUE > 0
    false true error other
  23. 23.以下表达式的运行结果是? [1 < 2 < 3, 3 < 2 < 1]
    [true, true] [true, false] error other
  24. 24.以下表达式的运行结果是? 2 == [[[2]]]
    true false undefined other
  25. 25.以下三个表达式的运行结果是? 3.toString() ; 3..toString() ; 3...toString()
    "3", error, error "3", "3.0", error error, "3", error other
  26. 26.以下表达式的运行结果是? (function(){ var x = y =1; })(); console.info(y); console.info(x);
    1, 1 error, error 1, error other
  27. 27.以下两个表达式的运行结果是? var a = /123/, b = /123/; console.log(a == b); console.log(a === b);
    true, true true, false false, false other
  28. 28.以下四个表达式的运行结果是? var a = [1, 2, 3], b = [1, 2, 3], c = [1, 2, 4]; a == b; a === b; a > c; a < c
    false, false, false, true false, false, false, false true, true, false, true other
  29. 29.以下表达式的运行结果是? var a = {}, b = Object.prototype; [a.prototype === b, Object.getPrototypeOf(a) === b]
    [false, true] [true, true] [false, false] other
  30. 30.以下表达式的运行结果是? function f() {} var a = f.prototype, b = Object.getPrototypeOf(f); a === b
    true false null other
  31. 31.以下表达式的运行结果是? function foo() { } var oldName = foo.name; foo.name = "bar"; [oldName, foo.name]
    error ["", ""] ["foo", "foo"] ["foo", "bar"]
  32. 32.以下表达式的运行结果是? "1 2 3".replace(/\d/g, parseInt)
    "1 2 3" "0 1 2" "NaN 2 3" "1 NaN 3"
  33. 33.以下表达式的运行结果是? function f() {} var parent = Object.getPrototypeOf(f); f.name // ? parent.name // ? typeof eval(f.name) // ? typeof eval(parent.name) // ?
    "f", "", "function", "function" "f", undefined, "function", error "f", "", "function", "undefined" other
  34. 34.以下表达式的运行结果是? var lowerCaseOnly = /^[a-z]+$/; [lowerCaseOnly.test(null), lowerCaseOnly.test()]
    [true, false] error [true, true] [false, true]
  35. 35.以下表达式的运行结果是? [,,,].join(", ")
    ", , , " "undefined, undefined, undefined, undefined" ", , " ""
  36. 36.以下表达式的运行结果是? var a = {class: "Animal", name: 'Fido'}; a.class
    "Animal" Object an error other
  37. 37.以下表达式的运行结果是? new Date("epoch")
    Thu Jan 01 1970 01:00:00 GMT+0100 (CET) current time error other
  38. 38.以下表达式的运行结果是? var a = Function.length, b = new Function().length; a === b
    true false error other
  39. 39.以下表达式的运行结果是? var a = Date(0); var b = new Date(0); var c = new Date(); [a === b, b === c, a === c]
    [true, true, true] [false, false, false] [false, true, false] [true, false, false]
  40. 40.以下表达式的运行结果是? var min = Math.min(), max = Math.max(); min < max
    true false error other
  41. 41.以下表达式的运行结果是? function captureOne(re, str) { var match = re.exec(str); return match && match[1]; } var numRe = /num=(\d+)/ig, wordRe = /word=(\w+)/i, a1 = captureOne(numRe, "num=1"), a2 = captureOne(wordRe, "word=1"), a3 = captureOne(numRe, "NUM=2"), a4 = captureOne(wordRe, "WORD=2"); [a1 === a2, a3 === a4]
    [true, true] [false, false] [true, false] [false, true]
  42. 42.以下表达式的运行结果是? var a = new Date("2014-03-19"), b = new Date(2014, 03, 19); [a.getDay() === b.getDay(), a.getMonth() === b.getMonth()]
    [true, true] [true, false] [false, true] [false, false]
  43. 43.以下表达式的运行结果是? if ('http://giftwrapped.com/picture.jpg'.match('.gif')) { 'a gif file' } else { 'not a gif file' }
    'a gif file' 'not a gif file' error other
  44. 44.以下表达式的运行结果是? function foo(a) { var a; return a; } function bar(a) { var a = 'bye'; return a; } [foo('hello'), bar('hello')]
    ["hello", "hello"] ["hello", "bye"] ["bye", "bye"] other

译自: http://javascript-puzzlers.herokuapp.com/

翻译中添加了个人理解,不好和有错的地方还请评论斧正