-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_site |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
layout: page | ||
title: 2016年Js知识点 | ||
categories: [笔记] | ||
tags: [2016,JS知识,个人,前端] | ||
--- | ||
|
||
自己平时收集的JS小知识点。 | ||
|
||
### 1. void 0 | ||
```js | ||
typeof void 0 //"undefined" | ||
undefined === void 0 //true | ||
undefined == void 0 //true | ||
null == void 0 //true | ||
"undefined" == void 0 //false | ||
``` | ||
|
||
### 2. null | ||
`undefined` 表示未定义 ; `null`表示值为空。 | ||
|
||
```js | ||
typeof null //"object" | ||
undefined == null //true | ||
undefined === null //false | ||
``` | ||
|
||
### 3. 正负无穷大 | ||
```js | ||
Infinity //Infinity | ||
1.7976931348623157E+1030899 //Infinity | ||
-1.7976931348623157E+1030899 //-Infinity | ||
``` | ||
|
||
### 4. Fisher-Yates shuffle 洗牌算法 | ||
洗牌算法: [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle). | ||
|
||
```js | ||
var shuffle = function(arr , n) { | ||
if (n == null) n = Infinity; | ||
var n = Math.max(Math.min(n, arr.length), 0); | ||
var last = arr.length - 1; | ||
for (var index = 0; index < n; index++) { | ||
var rand = random(index, last); | ||
var temp = arr[index]; | ||
arr[index] = arr[rand]; | ||
arr[rand] = temp; | ||
} | ||
return arr.slice(0, n); | ||
}; | ||
|
||
var random = function(min, max) { | ||
if (max == null) { | ||
max = min; | ||
min = 0; | ||
} | ||
return min + Math.floor(Math.random() * (max - min + 1)); | ||
}; | ||
``` |