Data type
underfined, null, 0, false, NaN, empty string. Their logical negation results are all true.
Closure format
Benefits: Avoid naming conflicts (global variable pollution).
(function(a, b) { console.log(a+b); //30 })(10, 20);
Intercept and clear the array
var arr = [12, 222, 44, 88]; arr.length = 2; //截取,arr = [12, 222]; arr.length = 0; //清空,arr will be equal to [].
Get the maximum and minimum values of the array
var numbers = [5, 45822, 120, -215]; var maxInNumbers = Math.max.apply(Math, numbers); //45822 var minInNumbers = Math.min.apply(Math, numbers); //-215
Floating point calculation problem
0.1 + 0.2 == 0.3 //false
Why? Because 0.1+0.2 is equal to 0.30000000000000004. JavaScript numbers are constructed according to the IEEE 754 standard and are internally represented as 64-bit floating point decimals. This problem can be solved by using toFixed().
Array sort sort function
var arr = [1, 5, 6, 3]; //数字数组 arr.sort(function(a, b) { return a - b; //从小到大排 return b - a; //从大到小排 return Math.random() - 0.5; //数组洗牌 }); var arr = [{ //对象数组 num: 1, text: 'num1' }, { num: 5, text: 'num2' }, { num: 6, text: 'num3' }, { num: 3, text: 'num4' }]; arr.sort(function(a, b) { return a.num - b.num; //从小到大排 return b.num - a.num; //从大到小排 });
Conversion of objects and strings
var obj = {a: 'aaa', b: 'bbb'}; var objStr = JSON.stringify(obj); // "{"a":"aaa","b":"bbb"}" var newObj = JSON.parse(objStr); // {a: "aaa", b: "bbb"}
git notes
git uses the previous configuration
1.git config --global user.email xxx@163.com
2.git config --global user.name xxx
3.ssh-keygen -t rsa -C xxx@163.com (email address) // Generate ssh
4. Found. Open the ssh folder, use cat id_rsa.pub //Open the public key ssh string
5. Log in to github, settings - SSH keys - add ssh keys (just add all the above content)
Note: Then the account corresponding to this email address (xxxxx@gmail.com) will have permission to operate the warehouse on github. You can freely perform the following git commands.
Common git commands
1. git config user.name / user.email //View the current git user name and email
2. git clone project //Clone the warehouse locally.
3. Modify the local code and submit it to the branch: git add file / git commit -m "New file"
4. Push the local library to the remote library: git push origin master
5. View the commit log: git log -5
6. Return to a certain version: git reset --hard 123
7. Branch: git branch / git checkout name / git checkout -b dev
8. Merge the name branch to the current branch: git merge name / git pull origin
9. Delete the local branch: git branch -D name
10. Delete the remote branch: git push origin :daily/x.x.x
11. git checkout -b mydev origin/daily/1.0.0 //Map the remote daily branch to the local mydev branch for development
12. Merge the remote branch to the current branch git pull origin daily/1.1.1
13. Publish online:
git tag publish/0.1.5
git push origin publish/ 0.1.5:publish/0.1.5
14. Online code coverage to local:
git checkout --theirs build/scripts/ddos
git checkout -- theirs src/app/ddos
The above is the detailed content of Detailed explanation of javascript data types and git usage code. For more information, please follow other related articles on the PHP Chinese website!