js basics interview summary

1, several types of data, which is a value type, which is a reference type
Data type: number string boolean null undefined object array function
value types: number, string, boolean, undefined , null
reference type: Object function Array
2, how to add a dom object to the body in? What is the difference innerText innerHTML and
add objects to the body in dom:
var div = document.createElement ( "div");
document.body.appendChild (div);
innerHTML: the object from an initial position to an end position of the entire content, comprising Html tags;
innerText: from the starting position to the end position of the content, but it is the removal of Html tags;
3, commissioned by the event? what is the benefit?
Event delegates is to use the principle of bubbling, the event will be added to the parent element or ancestor elements, trigger implementation of the results;
benefits:
(1) improve the performance of JS;
(2) can dynamically add DOM elements, the elements and do not need to change because modify event binding.
4, node type? How to determine the node type? (Description of common attributes)
node types: Node element (div, p, ul, etc.), a node attribute (id, class, name), text nodes (nodes or text content element attributes node), comment node, document node.
Analyzing node types: nodetype, nodename, nodevalue.
5, the difference between null and undefined?
Undefined type has only one value, that is undefined. When the variable declaration has not been initialized, the default variable is undefined.
Null type is only one value, that is null. null object has not been used to indicate the presence, used to indicate the function attempts to return an object that does not exist.
6, Js string manipulation functions
indexOf () -------- string search string return position, if not found returns -1
match () -------- specified search string, found Return the string, does not return null
replace ( "content is replaced by", "replace new content")
the toUpperCase () -------- uppercase
toLowerCasw () -------- converted into lowercase
Split ( "spacer") -------- string converted into an array of
the charAt (n) returns the specified position -------- first character position n is 0
Slice (Start, End ) -------- trailer header does not refer to the word string position taken
substring (start position of the index value, [end position index]) -------- header does not include the tail, position of the symbol index
substr (start, length) -------- taken taken start position start string length, length represents the length of the intercept
trim () -------- removing empty string ends
Splice: interception string, a first index indicates the starting position, a second value represents the length of the intercept, executing the influence of the string;
. 7, how detected data types Js? Ways?
typeOf
instanceOf
8, what is js garbage collection?
Resolve memory leaks, garbage collection periodically (periodic) to find that memory no longer used (variable), then release its memory.
9, the difference between null and undefined?
Undefined type has only one value, that is undefined. When the variable declaration has not been initialized, the default variable is undefined.
Null type is only one value, that is null. null object has not been used to indicate the presence, used to indicate the function attempts to return an object that does not exist.

Guess you like

Origin blog.51cto.com/14584021/2465242