今天在知乎上看到一篇JavaScript技巧,学习并收藏之
1. 快速打印一个五分制的评分情况
function getRating(rating) {
if(rating > 5 || rating < 0) throw new Error(‘数字不在范围内‘);
return ‘★★★★★☆☆☆☆☆‘.substring(5 - rating, 10 - rating );
}
2.拼接重复字符串(abcabcabc)
//输出n个‘abc’拼接的字符串
var str = new Array(n+1).join(‘abc‘);
- false => ![]
- true => !![]
- undefined => [][[]]
- NaN => +[![]]
- 0 => +[]
- 1 => +!+[]
- 2 => !+[]+!+[]
- 10 => [+!+[]]+[+[]]
- Array => []
- Number => +[]
- String => []+[]
- Boolean => ![]
- Function => []["filter"]
- eval => []["filter"]["constructor"]( CODE )()
- window => []["filter"]["constructor"]("return this")()
来源: <http://www.jsfuck.com/>
时间: 2024-12-04 18:20:02