JS Key Summary (ii)

Source: Internet
Author: User

1. function declaration and function Expression
(1) Variable declaration will be pinned in advance, but the assignment is still in the original place
(2) The function declaration is the same as the variable declaration, but the function expression does not advance, it is equivalent to the usual variable assignment
(3) The function declaration overrides the variable declaration, but does not override the variable assignment: the function declaration takes precedence over the precedence of the variable declaration, but after the variable is assigned, the variable assignment initializes the function declaration.
2. Function Arguments Property initialization:
(1) callee: Reference to the current function
(2) Length: The number of parameters actually passed
(3) If the index value of arguments is less than the number of parameters, then the value of the value is shared with the actual parameter, and if it is greater than, it is not shared, and it is irrelevant.
3, and, or, the NOT operator is detailed:
and: (1) An object is a Boolean, the returned object (2) 2 are objects that return the second (3) one is null or NAN, return null or Nan (4) Some is undefined error (5) 2 are Boolean, return Boolean
Or: (1) An object is a Boolean, and the returned object (2) 2 is the object that returns the first (3) one that is null or NAN, which returns null or Nan (4) Some undefined an error occurred
Not : (1) is an object, returns False (2) is 0 returns true, otherwise false (3) is null or Nan, returns true; undefined error occurred
Tip: Use 2 not operators to determine the Boolean value of a variable (the first not returns a Boolean value, and the second not gets the true Boolean value of the variable)
4, performance optimization:
(1) Avoid global lookups: Store global variables with local variables to reduce global lookups because global lookups need to always find the top of the scope chain
(2) Timer: Use less settimeout, because settimeout Initializes a timer every time, and setinterval Initializes a timer only at the beginning
(3) string connection less than + =, if you need to do the same string + = operation, you can use the array to cache, and then join method to connect
(4) number converted to string: "" + > String () > ToString () > New string ()
(5) floating point to integral type recommended with Math.floor () or Math.Round (), parseint more used to convert a string to a number
(6) Multiple variable declarations, using a single var form to reduce script execution time
(7) More use of direct volume is better, such as: var array = [];
(8) using document fragmentation to build the DOM structure: document.createdocumentfragment ()
(9) using innerHTML assignment instead of building DOM elements
(10) Try to use a more accurate selector, reduce the search time; for the sibling element, subset elements, etc. is the same reason, as far as possible to locate more accurate, avoid the loop
(11) before deleting the DOM node, be sure to delete the event registered on that node, otherwise it will produce the memory that cannot be reclaimed;
Also, select the latter between RemoveChild and innerhtml= "" because the DOM node cannot be effectively freed with RemoveChild
(12) Using the event proxy
(13) The result of repeated use, save to local variable, avoid the call cost of multiple values

JS Key Summary (ii)

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.