Javascript basis of (theoretical knowledge)

01, JavaSript which garbage collection mechanisms?

Clear labeling (mark and sweep)

JavaScr i pt This is the most common form of garbage collection. When the variable into the execution environment, such as declaring a variable in the function, the garbage collector to mark it as "into the environment." When leaving the environment variable (function performs end), it is marked as "to leave the environment." Garbage collector for all variables stored in memory at run time tagged, then remove the environment variables, and variables (closures) signs are referenced by the environment variable. Mark is the variable to be deleted after the completion of these still exist.

 

Reference count (reference counting)

Often a memory leak occurs in the low version of IE, many times, because it uses reference counting approach to garbage collection. The strategy is to reference count value is used for each frequency and track record. When declaring a variable and a time type assigned to the variable is referenced, the number of reference value is increased by one. If the value of the variable number into a reference to another, this value is decreased by 1. When this value is a reference number becomes 0, indicating that no variable is in use, this value can not be accessed. Therefore, it takes up space can be recovered, so the garbage collector will clean up the reference number of the space occupied by the value 0 at run time. Although in IE JavaScript object is labeled by a garbage collection to clear, but the BOM is a garbage DOM object using reference counts. In other words, as far as BOM and DOM, there will be a circular reference problem.

 

02, to name a few types of node DO M

The following categories DOM node.

• The entire document is a document (Document) section, point.

• Each HTML tag is an element (E l ement) node.

• Every HTML attribute is an attribute (Attribute) node. The text elements included in the HTML text (Text) node.

 

 

03, talk about the difference JavaSript tab defer and async attribute.

(1) defer attribute specifies whether to delay execution of the script until the page is loaded so far. async attribute specifies the script, once available, will execute asynchronously.

(2) defer the parallel load JavaScript files, will be executed in the order page script tag. async parallel load JavaScript file, the download is complete executed immediately, the order is not executed JavaScript tag on the page.

 

04, talk about your understanding of the closures.

Using closures designed primarily to support proprietary method and amount. Closure advantage is that contamination can be avoided global variables;

The disadvantage is that the closure will be permanent memory, increased memory usage, improper use is likely to cause a memory leak.

In JavaScript, functions, namely closure, will produce only function scope.

Closures have three characteristics.

(I) function nested function.

(2) may refer to external parameters and the amount of branching within the function.

(3) the parameters and variables will not be recovered in the garbage collection mechanism.

 

 

05, explain unshift () method.

The function startup method in an array, and push () are different. It parameters members added to the top of the array. The following presents an example code snippet.

var name = [ "] Ohn"] the unshift name ( " char Lie"); (, "] oseph" "Jane" name unshi. ft );; cons OLE log (name) 

represented by the following raw output port. [ "Joseph H," Jane " ," char lie "," john "]

 

 

06, What is the role encodeURI () and decodeURI () is?

encodeURI () is used to convert hexadecimal URL encoded. The decodeURI () is used to convert encoded URL back to normal URL.

 

 

07, why not recommend the use of innerHTML in JavaScript?

Modified by innerHTML content, refreshed every time, so it is slow. No opportunity to verify in innerHTML, and therefore easier to insert the error code in the document, the page is unstable.

 

 

08, how old does not support JavaScript browser hidden JavaScrpit Code?

Added after the code <script> tags "<! A", without quotation marks.

Add "knife ...>" before </ script> tag, no code marks.

Old browser JavaScript code will now be treated as a long HTML comment, and JavaScript-enabled browsers will be "<! A" and "// ...>" as a one-line comment.

 

 

09, how to create the DOM operation, add, remove, replace, insert and find nodes?

Specific methods are as follows.

(1) Create a new node with the following code. createDocurnentFragrnent () // create a DOM fragment

                createElernent () // create a specific element

                creat eTextNode () // Create a text node

(2) by adding the following code removal, substitution, insertion section point.

appendChild()

removeChild ( )

replaceChild ()

insertBefore () // no R & lt TAF T ER InSe ()
(. 3) Find the node with the following code.

getElernentsByTagNarne () // find node label name

getE l erne port tsByNarne () // find the value of the name attribute of the node element (IE strong fault tolerance, will be a number                                           

                // set, including a node name id equal value)

getElernentByid () // by elemental Id find the node, unique

 

 

 

10, how to achieve communication between multiple tabs within the browser?

Call Jocalstorge, cookie data storage and other means of communication.

Guess you like

Origin www.cnblogs.com/ZXH-null/p/12105452.html