网上整理了部分JS题以供学习,并且检验自己的学习理解JS的程度
每个问题答案都 缩进起来了---自己想出结果可以查看答案对比
第1题
1 |
["1", "2", "3"].map(parseInt) |
输出的结果是什么?
第2题
1 |
[typeof null, null instanceof Object] |
结果是什么??
第3题
1 2 |
[ [3,2,1].reduce(Math.pow), [].reduce(Math.pow) ] |
输出结果是答案是?
第4题
1 2 3 |
var val = 'smtg'; console.log('Value is ' + (val === 'smtg') ? 'Something' : 'Nothing'); |
打印出来的结果是什么?
第5题
1 2 3 4 5 6 7 8 9 10 |
var name = 'World!'; (function () { if (typeof name === 'undefined') { var name = 'Jack'; console.log('Goodbye ' + name); } else { console.log('Hello ' + name); } })(); |
最终会打印出来的结果为??
第6题
1 2 3 4 5 6 7 8 |
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题
1 2 3 4 |
var ary = [0,1,2]; ary[10] = 10; ary.filter(function(x) { return x === undefined;}); |
最终ary输出的结果是??
第8题
1 2 3 4 5 6 |
var two = 0.2 var one = 0.1 var eight = 0.8 var six = 0.6 console.log( [two - one == one, eight - six == two] ); |
在[]中输出的结果是???
第9题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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!'); } } showCase2(String('A')); |
第11题
1 2 3 4 5 6 7 8 9 10 11 12 |
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题
1 2 3 4 |
parseInt(3, 8) parseInt(3, 2) parseInt(3, 0) |
三次parseInt分别输出的结果是什么?
第13题
1 2 |
Array.isArray( Array.prototype ) |
返回的结果是??
第14题
1 2 3 4 5 6 |
var a = [0]; if ([0]) { console.log(a == true); } else { console.log("wut"); } |
第15题
1 2 3 |
[]==[] // 对比的结果? |
二者对比返回的结果是??
第16题
1 2 3 |
var num1 = '5' + 3 var num2 = '5' - 3 console.log(num1,num2) |
输出的num1和num2结果是??
第17题
1 2 3 |
1 + - + + + - + 1 |
最终的答案是?
第18题
1 2 3 4 |
var ary = Array(3); ary[0]=2 ary.map(function(elem) { return '1'; }); |
ary.map后输出的是什么???
第19题
1 2 3 4 5 6 7 8 9 10 11 |
function sidEffecting(ary) { ary[0] = ary[2]; } function bar(a,b,c) { c = 10 sidEffecting(arguments); return a + b + c; } bar(1,1,1) |
这是一个大坑, 尤其是涉及到 ES6语法的时候
第20题
1 2 3 4 5 |
var a = 111111111111111110000, b = 1111; a + b; |
a+b的结果是?
第21题
1 2 3 |
var x = [].reverse; x(); |
x()返回的是??
第22题
1 2 |
console.log( Number.MIN_VALUE > 0 ) |
打印结果是?
第23题
1 2 |
[1 < 2 < 3, 3 < 2 < 1] |
第24题
1 2 |
// the most classic wtf console.log( 2 == [[[2]]] ) |
第25题
1 2 3 4 |
3.toString() 3..toString() 3...toString() |
三次输出返回的结果是??
第26题
1 2 3 4 5 6 |
(function(){ var x = y = 1; })(); console.log(y); console.log(x); |
y和x分别的结果是?
第27题
1 2 3 4 5 |
var a = /123/, b = /123/; a == b a === b |
第28题
1 2 3 4 5 6 7 8 |
var a = [1, 2, 3], b = [1, 2, 3], c = [1, 2, 4] a == b a === b a > c a < c |
四次对比的结果分别是??
第29题
1 2 3 |
var a = {}, b = Object.prototype; [a.prototype === b, Object.getPrototypeOf(a) === b] |
在[]中,二次对比的结果是什么?
第30题
1 2 3 4 |
function f() {} var a = f.prototype, b = Object.getPrototypeOf(f); a === b |
a===b结果是?
第31题
1 2 3 4 5 |
function foo() { } var oldName = foo.name; foo.name = "bar"; [oldName, foo.name] |
[oldName, foo.name]分别输出结果是?
第32题
1 2 |
"1 2 3".replace(/\d/g, parseInt) |
最终答案是什么?
第33题
1 2 3 4 5 6 7 |
function f() {} var parent = Object.getPrototypeOf(f); f.name // ? parent.name // ? typeof eval(f.name) // ? typeof eval(parent.name) // ? |
第34题
1 2 3 |
var lowerCaseOnly = /^[a-z]+$/; [lowerCaseOnly.test(null), lowerCaseOnly.test()] // []中的结果是?? |
第35题
1 2 |
[,,,].join(", ") |
返回来的结果是??
第36题
1 2 3 |
var a = {class: "Animal", name: 'Fido'}; a.class |
第37题
1 2 |
var a = new Date("epoch") |
第38题
1 2 3 4 |
var a = Function.length, b = new Function().length a === b |
第39题
1 2 3 4 5 |
var a = Date(0); var b = new Date(0); var c = new Date(); [a === b, b === c, a === c] |
第40题
1 2 3 |
var min = Math.min(), max = Math.max() min < max // 对比结果是? |
第41题
1 2 3 4 5 6 7 8 9 10 11 12 |
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] // []中结果分别是多少 |
第42题
1 2 3 4 5 |
var a = new Date("2014-03-19"), b = new Date(2014, 03, 19); [a.getDay() === b.getDay(), a.getMonth() === b.getMonth()] // []中的结果 |
第43题
1 2 3 4 5 6 |
if ('http://giftwrapped.com/picture.jpg'.match('.gif')) { 'a gif file' } else { 'not a gif file' } |
第44题
1 2 3 4 5 6 7 8 9 10 |
function foo(a) { var a; return a; } function bar(a) { var a = 'bye'; return a; } [foo('hello'), bar('hello')] // []中的结果 |
全部结束!
总结
由于笔者水平有限, 如果解释有误, 还望指出 😄
通过整理, 笔者发现绝大部分题目都是因为自己对于基础知识或者说某个 API 的参数理解偏差才做错的.