Error-prone front-end problem

1.js There are several types of data, which the basic data types What are
five basic types: Undefined, Null, Boolean, Number, and String.
Reference types: Object, Array and Function.

2.px em and differences
px represent pixels), it is absolute units, and does not change the size of other elements changes;
em represents the font size relative to the parent element. em relative units is not a fixed measure, but the relative value is determined by the dimensions of the other elements.

3.JS What action will cause a memory leak

(1) memory leaks caused by unexpected global variables.
Leak function () {  
  Leak = "XXX"; // Leak be a global variable, not be recovered  
}
(2) caused by closures memory leak.
(3) does not clean up the DOM element reference.
(4) Forgotten or timer callback, a memory leak caused by the sub-elements.

4. How to add, remove, move, copy, create, and find nodes?

(1) Create a new node
createDocumentFragment () // creates a DOM fragment
createElement () // create a concrete element
createTextNode () // Create a text node
(2) is added, removed, replaced, inserted
appendChild () // Add
removeChild () // remove
replaceChild () // Alternatively
insertBefore () // insert
(3) Find
getElementsByTagName () // tag name by
getElementsByName () // a value of the name attribute element
getElementById () // by elements Id, uniqueness

5. What type of data returned, typeof javascript.

string,boolean,number,undefined,function,object

6. include three kinds of casts and two kinds of implicit type conversion?

Forced (parseInt, parseFloat, number)
implicitly (== ===)

7. () the difference between split join () of

The former is an array of strings is cut, which is to convert the array into a string

 What 8.new specific operator did it?

1. Create an empty object, and this variable refers to the object, also inherits the prototype of the function.

2, the properties and methods of this reference is added to the object.

3, the newly created object referenced by this, and finally the implicit return this.

9. javascript is object-oriented, reflect how the javascript inheritance?

Use prototype prototype to achieve.

10 .form The input can be set to readonly and disable, 2 who ask what is the difference?

readonly not editable, but may select and copy; value can be passed back to the
disabled can not be edited, can not replicate, can not be selected; value is not passed to the background

11 Write three typical applications using this

Event: such as onclick this-> object event occurred
constructor this-> new out of the Object
Call / the Apply this change

12. What is undeclared and undefined variables?

Undeclared variable is not present in the program and did not declare variables. If the program tries to read the value of undeclared variables, runtime error is encountered. Undefined variable is declared in the program but has not given any value of the variable. If the program tries to read the value of the variable is undefined, undefined value is returned.

13. Write a method to remove duplicate content inside the array? (You can also use the object, it is more common to heavy)

var ARR = [ 'ABC', 'ABCD', 'sss', '2', 'D', 'T', '2', 'SS', 'F', '22 is', 'D'];
/ / define a new array
var S = [];
// iterate
for (var I = 0; I <arr.length; I ++) {
    IF (s.indexOf (ARR [I]) == -1) {/ / s is determined whether there is an array, it does not exist to push the array s
        s.push (ARR [I]);
    }
}
the console.log (s);
// output results: [ "abc", "abcd ", "sss", "2", "d", "t", "SS", "f", "22"] 14. The closure of what is, how to use it, why use it?

Closure to read other functions is a function of internal variables. Since the Javascript language, only the internal function subroutine to read local variables, the closure can be simply interpreted as "a defined function within the function."
Therefore, in essence, the closure is an internal bridge function and the function of connecting external. Closures can be used in many places. It's most useful for two, one is the aforementioned variables can be read inside the function, and the other is to make the values of these variables remain in memory.
Use closures Precautions:
• Since the closure will make the function of the variables are stored in memory, memory consumption is large, it can not be abused closure, otherwise it will cause performance problems webpage in IE may lead to memory leaks . The solution is, before exiting the function will delete all local variables are not used.
· Closures function outside the parent, the parent function changes the value of the internal variable. So, if you take the parent function as an object (object) to use, the closure of its public methods (Public Method) as, the internal variable as its private property (private value), then you must be careful not to just change the value of the parent function of internal variables

Guess you like

Origin www.cnblogs.com/zhangli123/p/11404007.html