JS Reading Summary

Source: Internet
Author: User

1. Number:
Nan is a result of an operation that does not produce normal results. The function isNaN (number) can be used to detect Nan;
The Math.floor method can convert a number to an integer;
=============================================================================================================== ===================================
2. These listed values are treated as false (false): false, null, undefined, empty string "", number 0, and number nan;
=============================================================================================================== ===================================
3, ternary operator:
Format: (conditional expression)? Expression 1: expression 2;//: int a = 10; int b = (a==b)? 10:20; Result is 20
If the expression arithmetic value is true, Ze produces the value of the second operand, and if false, produces the value of the third operand.
=============================================================================================================== ===================================
4. Search:
var stu = {"first_name": "Jack"}
Stu.first_name or stu["first_name"]//Running results jack
|| The operator can be used to populate the default values:
var stu_mid = stu["Mid_name"] | | "(none)";
=============================================================================================================== ===================================
5. Reduce the pollution of global variables: (Create only one unique global variable for the application and make this variable a container):
var vessel = {};
Vessel.one = "text";//The value of text can be obtained by vessel.one in the whole JS
=============================================================================================================== ===================================
6. Apply Call Mode: (the Apply method has two parameters, one is the value to bind to this, and one is the parameter array)
var add = function (A, b) {
return a + B;
};
var array = [3, 4];
var sum = add.apply (null, array); The value of//sum is 7;
=============================================================================================================== ===================================
7. Method:
1) Array:
Array.concat (item): Concat method produces a new array, similar to Array.push (item)
var a = [' A ', ' B ', ' C '];
var b = [' X ', ' y ', ' Z ']
var C = A.concat (b, true);//c becomes [' A ', ' B ', ' C ', ' X ', ' y ', ' z ', True]
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Array.join (separator): Separator default, separated, if you want to splice the empty string ""
var a = [' A ', ' B ', ' C '];
A.push (' d ');
var c = a.join (")//c for ' ABCD '
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Array.pop (): Removes the last element in the array and returns the element--its corresponding method Array.shift (): Removes the first element and returns the element
var a = [' A ', ' B ', ' C '];
var c = A.pop ();//a is [' A ', ' B '] & C is ' C '
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Array.push (Item ...): Appends one or more parameters to the end of an array--array.unshift (item:) Attaches one or more parameters to the head of an array
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Array.reverse (): Flips the order of elements in an array
var a = [' A ', ' B ', ' C '];
var B = A.reverse ();//a and B are [' C ', ' B ', ' a ']
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Array.slice (Start, end): Copy from start to end, default end to array length
var a = [' A ', ' B ', ' C '];
var b = A.slice (0, 1);//b is [' a ']
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Array.Sort (COMPAREFN): Sorts the contents of an array, but only for strings, and if you want to sort on a number, the following methods are available:
var n = [4,8,15,16,23,42];
N.sort (function (b) {
return a-B;
});//n is [4,8,15,16,23,42]
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Array.splice (Start, DeleteCount, item): Removes one or more elements and replaces them with item
var a = [' A ', ' B ', ' C '];
var r = A.splice (1, 1, ' ache ', ' bug ');
A is [' a ', ' ache ', ' Bug ', ' C '] r is [' B ']
--------------------------------------------------------------------------------------------------------------- -----------------------------------
2) String:
String.charat (Index): Returns the character code point of the character at the index position in the string--string.charcodeat (index) that is returned by this position
var name = ' Curly ';
var end = Name.charat (0);//end is C
--------------------------------------------------------------------------------------------------------------- -----------------------------------
String.Concat (string.): equivalent to the string + up, less use, because with + convenient
--------------------------------------------------------------------------------------------------------------- -----------------------------------
String.match (RegExp): This method matches a string to a regular expression, depending on the G representation to determine how to match
var a =/regular expression/g;
var b = ' aaaaa ';
var i = B.match (a);
--------------------------------------------------------------------------------------------------------------- -----------------------------------
String.Replace (Searchvalue, Replacevalue): Finding and replacing
Searchvalue if it is a regular expression with a G-id, ze replaces all matching
--------------------------------------------------------------------------------------------------------------- -----------------------------------
String.slice (Start, end): Copy from start to end, default end to array length
var text = ' and in it ';
var a = Text.slice (0, 3);//a is ' and '
--------------------------------------------------------------------------------------------------------------- -----------------------------------
String.Split (separator, limit): Splits a string to create an array of characters, and limit is an optional parameter that shows the number of split fragments
var text = ' 0123456789 ';
var a = Text.split (', 5);//a is [' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ']
--------------------------------------------------------------------------------------------------------------- -----------------------------------
String.substring (Start,end): Similar to slice, except that this cannot handle negative integer parameters
--------------------------------------------------------------------------------------------------------------- -----------------------------------
String.tolowercase (): Convert all to lowercase format;
String.touppercase (): Convert all to uppercase format;
--------------------------------------------------------------------------------------------------------------- -----------------------------------
String.fromCharCode (char.): Returns a string based on numeric encoding
var a = String.fromCharCode (67,97,116);//a is ' Cat '
=============================================================================================================== ===================================
8. typeof Operator:
typeof 98;//return number
typeof "98";//returns string
typeof null;//returns object instead of NULL
=============================================================================================================== ===================================
9, parseint () most commonly used, can filter out non-numeric characters, such as 123blue will be converted to 123;
parseint ("08");//will get 0
parseint ("08", 10);//The result is 8. It is therefore recommended to add this count parameter.
=============================================================================================================== ===================================
10, try to use = = = and! = =, avoid using = = and! =
=============================================================================================================== ===================================



JS Reading Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.