《44个Javascript变态题》
第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 arr = [0,1,2];
arr[10] = 10;
arr.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('unknown');
            break;
    }
}
showCase(new String('A'))第10题
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('unknown');
            break;
    }
}
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题
Array.isArray(Array.prototype);第13题
var a = [0];
if([0]){
    console.log(a == true);
}else{
    console.log('wut');
}第14题
parseInt(3, 8);
parseInt(3, 2);
parseInt(3, 0);第15题
[] == [];第16题
'5' + 3;
'5' - 3;第17题
1 + - + + + - + 1第18题
var arr = Array(3);
arr[0] = 2;
arr.map(function(item){
    return '1';
});第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);第20题
var a = 11111111111111000;
var b = 111;
console.log(a + b);第21题
var x = [].reverse;
x();第22题
Number.MIN_VALUE > 0;
// MIN_VALUE 属性是 JavaScript 中可表示的最小的数(接近 0 ,但不是负数)。它的近似值为 5 x 10-324第23题
[1 < 2 < 3, 3 < 2 < 1];第24题
2 == [[[2]]]第25题
3.toString();
3..toString();
3...toString();第26题
(function(){
    var x = y = 1;
})();
x;
y;第27题
var a = /123/;
var b = /123/;
a == b;
a === b;第28题
var a = [1, 2, 3];
var b = [1, 2, 3];
var c = [1, 2, 4];
a == b;
a === b;
a > c;
a < c;第29题
var a = {};
var b = Object.prototype;
[a.prototype === b, Object.getPrototypeOf(a) === b];第30题
function f(){};
var a = f.prototype, b = Object.getPrototypeOf(f);
a === b;第31题
function foo(){}
var oldName = foo.name;
foo.name = 'bar';
[oldName, foo.name];第32题
'1 2 3'.replace(/\d/g,parseInt);第33题
function f(){}
var parent = Object.getPrototypeOf(f);
f.name; //?
parent.name; //?
typeof eval(f.name) //?
typeof eval(parent.name) //?第34题
var lowerCaseOnly = /^[a-z]+$/;
[lowerCaseOnly.test(null), lowerCaseOnly.test()];第35题
[,,,].join(', ');第36题
var a = {class:'Animal', name:'Fido'};
a.class;第37题
var a = new Date('epoch');第38题
var a = Function.length;
var b = new Function().length;
a === b;第39题
var b = Date(0);
var b = new Date(0);
var c = new Date();
[a === b, b === c, a === c]第40题
var min = Math.min(), max = Math.max();
min < max;第41题
function captureOne(re, str){
    var match = re.exec(str);
    return match && match[1];
}
var numRe = /num=(\d+)/ig;
var 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题
var a= new Date('2014-03-19');
var b =new Date(2014, 03, 19);
[a.getDay() === b.getDay(), a.getMonth() === b.getMonth()]第43题
if('http://xxxgif.com/picture.jpg'.match('.gif')){
    'a gif file'
}else{
    'note a git file'
}第44题
function foo(a){
    var a;
    return a;
}
function bar(a){
    var a = 'bye';
    return a;
}
[foo('hello'),bar('hello')];文章转自:https://segmentfault.com/a/1190000005883614
    心似浮云常自在,意如流水任东西
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号