资讯专栏INFORMATION COLUMN

转载:《44个Javascript{{BANNED}}题》

BDEEFE / 2036人阅读

摘要:第题第题第题第题第题第题第题第题第题第题第题第题第题第题第题第题第题第题第题第题第题第题属性是中可表示的最小的数接近,但不是负数。

第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://www.ucloud.cn/yun/79893.html

相关文章

  • 实用性前端知识 - 收藏集 - 掘金

    摘要:与面向对象编程六大方向助你突破前端生涯平台期前端掘金无论我们从事何种职业,在职业生涯的某个阶段,都或多或少会遇到所谓的平台期。目前为止,已经有个用户通过认证登观点年前端初学者的生存指南前端掘金逝者如斯夫,不舍昼夜。 你可能听说过函数式编程(Functional programming),甚至已经使用了一段时间。 但是,你能说清楚,它到底是什么吗? 网上搜索一下,你会轻松找到好多答案...

    Honwhy 评论0 收藏0
  • 深入理解js

    摘要:详解十大常用设计模式力荐深度好文深入理解大设计模式收集各种疑难杂症的问题集锦关于,工作和学习过程中遇到过许多问题,也解答过许多别人的问题。介绍了的内存管理。 延迟加载 (Lazyload) 三种实现方式 延迟加载也称为惰性加载,即在长网页中延迟加载图像。用户滚动到它们之前,视口外的图像不会加载。本文详细介绍了三种延迟加载的实现方式。 详解 Javascript十大常用设计模式 力荐~ ...

    caikeal 评论0 收藏0
  • 44JavaScript变态解析

    摘要:第题知识点首先接受两个参数一个回调函数一个回调函数的值其中回调函数接受三个参数而题目中只传入了回调函数其次只接受两个两个参数基数可选。 第1题 [1, 2, 3].map(parseInt) 知识点: Array/map Number/parseInt JavaScript parseInt 首先, map接受两个参数, 一个回调函数 callback, 一个回调函数的this值 ...

    aikin 评论0 收藏0
  • 大前端 - 收藏集 - 掘金

    摘要:是目前唯一一个支持同步调用的跨平台年度上最多的个项目前端掘金年接近尾声,在最近的几篇文章中,会整理总结一些年度开源项目。 JS 全栈教程 - 前端 - 掘金本课程是基于阮一峰的 js 全栈教程的视频版本,免费供大家观看... 2016 年 10 个最佳的 CodePen 作品 - 前端 - 掘金说到 CodePen,前端开发者们肯定不会陌生。如果说 Dribbble 是设计师们聚集的圣...

    honhon 评论0 收藏0

发表评论

0条评论

BDEEFE

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<