本文秉承着:你看不懂是你SB,我写的代码就要牛逼。
1、单行写一个评级组件
“★★★★★☆☆☆☆☆”.slice(5 – rate, 10 – rate);定义一个变量rate是1到5的值,然后执行上面代码,看图
才发现插件什么的都弱爆了
2、如何装逼用代码骂别人SB
(!(~ ) {})[--[~ ""][ ]*[~ ] ~~! ] ({} )[[~! ]*~ ]
4、JavaScript错误处理的方式的正确姿势
,舅服你
try{
something
}catch(e){
window.location.href=
"http://stackoverflow.com/search?q=
[js] " e.message;
}
5、论如何优雅的取随机字符串
Math.random.toString(16).substring(2)Math.random.toString(36).substring(2)
6、匿名函数自执行
这么多写法你选择哪一种?我选择死亡。
(function{});
(function{});
[function{}];
~function{};
!function{};
function{};
-function{};
deletefunction{};
typeoffunction{};
voidfunction{};
newfunction{};
newfunction{}
;varf=function{};
1function{};
1^function{};
1function{};// ...
7、论如何优雅的取整
vara=~~2.33
varb=2.33|0
varc=2.330
8、这个我服,还有这个你很机智
我服
while(1){
alert('牛逼你把我关了啊')
}
你很机智,好一个障眼法
清除缓存:<a href="javascript:alert('清除成功');"清除缓存</a
9、逗号运算符
vara=0;
varb=(a 99);
console.log(a);// 1
console.log(b);// 99
10、论如何最佳的让两个整数交换数值
常规办法:
vara=1
b=2;
a =b;
b=a-b;
a-=b;
缺点也很明显,整型数据溢出,对于32位字符最大表示数字是2147483647,如果是2147483645和2147483646交换就失败了。黑科技办法:
a^=b;
b^=a;
a^=b;
哈哈
,看不懂的童鞋建议去补习一下C语言的位操作,我就不去复习了,以前学嵌入式时候学的位操作都忘了
11、实现标准JSON的深拷贝
vara={
a:1b:{c:1d:2}
}
varb=JSON.parse(JSON.stringify(a))
不考虑IE的情况下,标准JSON格式的对象蛮实用,不过对于undefined和function的会忽略掉。
12、不用Number、parseInt和parseFloat和方法把”1″字符串转换成数字
哈哈,不准用强制类型转换,那么就想到了强大了隐式转换
vara=1
a
13、如何装逼的写出”hello world!”
滚动条很长哦
( [(! )[! !! !!] ( {})[ !!] (!! )[ !!] (!! )[ ]][( {})[! !! !! !! !!] ( {})[ !!] ([] )[ !!] (! )[! !! !!] (!! )[ ] (!! )[ !!] ([] )[ ] ( {})[! !! !! !! !!] (!! )[ ] ( {})[ !!] (!! )[ !!]]((!! )[ !!] ([] )[! !! !!] (!! )[ ] ([] )[ ] (!! )[ !!] ([] )[ !!] ( {})[! !! !! !! !! !! !!] (! )[! !!] ( {})[ !!] ( {})[! !! !! !! !!] ( {} )[ !!] (!! )[ ] ([] )[! !! !! !! !!] ( {})[ !!] ([] )[ !!]))[ ] ([] )[! !! !!] (! )[! !!] (! )[! !!] ( {})[ !!] ( {})[! !! !! !! !! !! !!] [(! )[! !! !!] ( {})[ !!] (!! )[ !!] (!! )[ ]][( {})[! !! !! !! !!] ( {})[ !!] ([] )[ !!] (! )[! !! !!] (!! )[ ] (!! )[ !!] ([] )[ ] ( {})[! !! !! !! !!] (!! )[ ] ( {})[ !!] (!! )[ !!]]((!! )[ !!] ([] )[! !! !!] (!! )[ ] ([] )[ ] (!! )[ !!] ([] )[ !!] ( {})[! !! !! !! !! !! !!] ([] )[ ] ([] )[ !!] ([] )[! !! !!] (! )[! !! !!] ( {})[! !! !! !! !!] ( {} )[ !!] ( [(! )[! !! !!] ( {})[ !!] (!! )[ !!] (!! )[ ]][( {})[! !! !! !! !!] ( {})[ !!] ([] )[ !!] (! )[! !! !!] (!! )[ ] (!! )[ !!] ([] )[ ] ( {})[! !! !! !! !!] (!! )[ ] ( {})[ !!] (!! )[ !!]]((!! )[ !!] ([] )[! !! !!] (!! )[ ] ([] )[ ] (!! )[ !!] ([] )[ !!] ( {})[! !! !! !! !! !! !!] (! )[! !!] ( {})[ !!] ( {})[! !! !! !! !!] ( {} )[ !!] (!! )[ ] ([] )[! !! !! !! !!] ( {})[ !!] ([] )[ !!]))[! !! !!] ([] )[! !! !!])([(! )[! !! !!] ( {})[ !!] (!! )[ !!] (!! )[ ]][( {})[! !! !! !! !!] ( {})[ !!] ([] )[ !!] (! )[! !! !!] (!! )[ ] (!! )[ !!] ([] )[ ] ( {})[! !! !! !! !!] (!! )[ ] ( {})[ !!] (!! )[ !!]]((!! )[ !!] ([] )[! !! !!] (!! )[ ] ([] )[ ] (!! )[ !!] ([] )[ !!] ( {})[! !! !! !! !! !! !!] ([] )[! !! !!] (! )[! !! !!] ( {})[! !! !! !! !!] ( {} )[ !!] ( [(! )[! !! !!] ( {})[ !!] (!! )[ !!] (!! )[ ]][( {})[! !! !! !! !!] ( {})[ !!] ([] )[ !!] (! )[! !! !!] (!! )[ ] (!! )[ !!] ([] )[ ] ( {})[! !! !! !! !!] (!! )[ ] ( {})[ !!] (!! )[ !!]]((!! )[ !!] ([] )[! !! !!] (!! )[ ] ([] )[ ] (!! )[ !!] ([] )[ !!] ( {})[! !! !! !! !! !! !!] (! )[! !!] ( {})[ !!] ( {})[! !! !! !! !!] ( {} )[ !!] (!! )[ ] ([] )[! !! !! !! !!] ( {})[ !!] ([] )[ !!]))[! !! !!] ([] )[! !! !!])(( {})[ ])[ ] (! !! !! !! !! !! !! ) (! !! !! !! !! !! !! )) ( {})[ !!] (!! )[ !!] (! )[! !!] ([] )[! !!] [(! )[! !! !!] ( {})[ !!] (!! )[ !!] (!! )[ ]][( {})[! !! !! !! !!] ( {})[ !!] ([] )[ !!] (! )[! !! !!] (!! )[ ] (!! )[ !!] ([] )[ ] ( {})[! !! !! !! !!] (!! )[ ] ( {})[ !!] (!! )[ !!]]((!! )[ !!] ([] )[! !! !!] (!! )[ ] ([] )[ ] (!! )[ !!] ([] )[ !!] ( {})[! !! !! !! !! !! !!] ([] )[ ] ([] )[ !!] ([] )[! !! !!] (! )[! !! !!] ( {})[! !! !! !! !!] ( {} )[ !!] ( [(! )[! !! !!] ( {})[ !!] (!! )[ !!] (!! )[ ]][( {})[! !! !! !! !!] ( {})[ !!] ([] )[ !!] (! )[! !! !!] (!! )[ ] (!! )[ !!] ([] )[ ] ( {})[! !! !! !! !!] (!! )[ ] ( {})[ !!] (!! )[ !!]]((!! )[ !!] ([] )[! !! !!] (!! )[ ] ([] )[ ] (!! )[ !!] ([] )[ !!] ( {})[! !! !! !! !! !! !!] (! )[! !!] ( {})[ !!] ( {})[! !! !! !! !!] ( {} )[ !!] (!! )[ ] ([] )[! !! !! !! !!] ( {})[ !!] ([] )[ !!]))[! !! !!] ([] )[! !! !!])([(! )[! !! !!] ( {})[ !!] (!! )[ !!] (!! )[ ]][( {})[! !! !! !! !!] ( {})[ !!] ([] )[ !!] (! )[! !! !!] (!! )[ ] (!! )[ !!] ([] )[ ] ( {})[! !! !! !! !!] (!! )[ ] ( {})[ !!] (!! )[ !!]]((!! )[ !!] ([] )[! !! !!] (!! )[ ] ([] )[ ] (!! )[ !!] ([] )[ !!] ( {})[! !! !! !! !! !! !!] ([] )[! !! !!] (! )[! !! !!] ( {})[! !! !! !! !!] ( {} )[ !!] ( [(! )[! !! !!] ( {})[ !!] (!! )[ !!] (!! )[ ]][( {})[! !! !! !! !!] ( {})[ !!] ([] )[ !!] (! )[! !! !!] (!! )[ ] (!! )[ !!] ([] )[ ] ( {})[! !! !! !! !!] (!! )[ ] ( {})[ !!] (!! )[ !!]]((!! )[ !!] ([] )[! !! !!] (!! )[ ] ([] )[ ] (!! )[ !!] ([] )[ !!] ( {})[! !! !! !! !! !! !!] (! )[! !!] ( {})[ !!] ( {})[! !! !! !! !!] ( {} )[ !!] (!! )[ ] ([] )[! !! !! !! !!] ( {})[ !!] ([] )[ !!]))[! !! !!] ([] )[! !! !!])(( {})[ ])[ ] (! !! ) ( !! ))
居然能运行,牛逼的隐式转换
14、parseInt(0.0000008) === 8
15、 [][ ] [ ] == 10
强大的隐式转换,23333
16、0.1 0.2 == 0.3
0.1 0.2 == 0.3竟然是不成立的。。。。所以这就是为什么数据库存储对于货币的最小单位都是分。
简单说,0.1和0.2的二进制浮点表示都不是精确的,所以相加后不是0.3,接近(不等于)0.30000000000000004。
所以,比较数字时,应该有个宽容值。ES6中这个宽容值被预定义了:Number.EPSILON。
17、最短的代码实现数组去重
[...newSet([1"1"2113])]
前不久面试阿里就问了这道题,哈哈,所以也写上一下
18、用最短的代码实现一个长度为m(6)且值都n(8)的数组
Array(6).fill(8)
这个够短了吧,好像是当初哪里看到的一个面试题,就自己想到了ES6的一些API
19、短路表达式
条件判断
vara=b&&1//相当于if(b){a=1}else{a=b}
vara=b||1//相当于if(b){a=b}else{a=1}24、
JavaScript版迷宫
逃出迷宫,2333
20、取出一个数组中的最大值和最小值
varnumbers=[5458120-215228400122205-85411];
varmaxInNumbers=Math.max.apply(Math numbers);
varminInNumbers=Math.min.apply(Math numbers);
最后奉劝大家一句:莫装逼、白了少年头,2333。。。
写在最后大咖的话:
“最近有很多想学习编程,学习技术的朋友问我有没有什么好的技术,编程资料,他们说想学习编程,学习技术,做一名程序员。因为最近今年我都在认真搜集有价值的编程资料,技术资料,只为帮助那些想学习编程,学习技术做程序员的朋友。
下图就是:
以上价值3万元的资料,绝对比群里那些漫天飞的资料强多了。今天决定免费分享,用来感谢大家的支持。”
获取方式:
关注头条号
给文章点赞
私聊小编即可获取大咖联系方式,免费领取价值3万元全套视频资料!不需要任何条件!
觉得不错请请点赞!
欢迎留言分享!
,