JavaScript Common interview topics
what data types are returned by the 1:javascript typeof?
Object number Functionboolean Underfind
------------------------------------------------------------------------------
2: How to determine whether a variable is an array data type.
· Method I. To determine whether it has "array properties", such as the slice () method. You can define the slice method for the variable and sometimes it will fail
· Method two. obj instanceof Array is incorrect in some versions of IE
· Method Three. Method one or two has vulnerabilities, the new method Array.isarray () is defined in ECMA Script5, and the best way to ensure its compatibility is as follows:
if (typeofarray.isarray=== "undefined")
{
Array.isarray = function (ARG) {
ReturnObject.prototype.toString.call (ARG) = = "[Object Array]"
};
}
------------------------------------------------------------------------------
3. Examples of 3 types of coercion and 2 implicit type conversions.
Coercion (Parseint,parsefloat,number)
Implicit (==–===)
------------------------------------------------------------------------------
4.split () join () the difference?
The former is the form of cutting the array, the latter is the conversion of arrays to strings
------------------------------------------------------------------------------
5. Array method Pop () push () unshift () Shift ( )
Push () tail add pop () tail delete
Unshift () head add Shift () head Delete
------------------------------------------------------------------------------
6: When a DOM node is clicked, we want to be able to perform a function and what should be done.
· Binding events directly in the DOM: <div onclick= "Test ()" ></div>
· In JS through the onclick binding: Xxx.onclick = Test
· Binding through Event additions: AddEventListener (XXX, ' click ', test)
------------------------------------------------------------------------------
what is in the 7:javascript event flow model.
· Event bubbling ": The event begins to be accepted by the most specific element and then propagated upward
· "Event capture": Events are received by the least specific node, then step down, all the time to the most specific
· "Dom Event Flow": Three phases: Event capture, target phase, event bubbling
------------------------------------------------------------------------------
What is the difference between 8.IE and DOM event streams?
1. The order of execution is different,
2. Different parameters
3. The event is not added on
4.this pointing problem
------------------------------------------------------------------------------
9.IE and what is the compatibility of the standard under the wording?
Var ev = EV | | Window.event
Document.documentElement.clientWidth | | Document.body.clientWidth
Var target = ev.srcelement| | Ev.target
------------------------------------------------------------------------------
What is the difference between get and post when a 10.ajax request is requested?
One behind the URL, one in the virtual carrier.
There is a size limit
Security issues
Application of a different one is a forum, etc. only need to request, one is similar to modify the password
------------------------------------------------------------------------------
What is the difference between 11.call and apply?
Object.call (THIS,OBJ1,OBJ2,OBJ3)
Object.apply (this,arguments)
------------------------------------------------------------------------------
12.ajax request, how do I interpret JSON data?
Using the Eval parse parse is more reliable in view of security considerations
------------------------------------------------------------------------------
13:ajax Synchronous and asynchronous differences, how to solve cross-domain problems?
Sync: Submitting requests-> waiting for server processing-> processing finished returning the client browser cannot do anything
Asynchronous: Request to trigger-> server processing via event (this is something that the browser can still do)-> processing complete
------------------------------------------------------------------------------
14. Write a function that gets a non-row style?
Functiongetstyle (obj,attr) {//Get non-row style, obj is Object, attr is value
if (Obj.currentstyle) {//Get non-row style for IE
return obj.currentstyle[attr];
}else{
Return getComputedStyle (Obj,false) [attr]; For non IE
};
};
------------------------------------------------------------------------------
15. What is an event delegate?
Using the bubbling principle, the event is added to the parent, triggering the execution effect.
In layman's terms, the event is onclick,onmouseover,onmouseout, and so is the event, commissioned, is to let others do, this event was added to some elements, but you add to others to do, complete this event.
------------------------------------------------------------------------------
16. What are closures, what are the characteristics, and what are the effects on the page?
Closures are functions that can read internal variables of other functions.
------------------------------------------------------------------------------
17. How do I prevent event bubbling and default events?
bubbling: if (e &&e.stoppropagation) {
//So it supports the Stoppropagation () method of the Consortium
e.stoppropagation ();
} else{
//Otherwise, we need to use IE to cancel event bubbling
window.event.cancelBubble = true;
}
Default Event:if (e && e.preventdefault) {
E.preventdefault ();
} else {
How to block the default action of a function in IE
Window.event.returnValue =false;
}
return false;
------------------------------------------------------------------------------
18. How do I add, remove, move, copy, create, and find nodes?
1) Create a new node
Createdocumentfragment ()//Create a DOM fragment
CreateElement ()//create a specific element
createTextNode ()//Create a text node
2) Add, remove, replace, insert
AppendChild ()//Add
RemoveChild ()//removal
ReplaceChild ()//Replace
InsertBefore ()//Insert
3) Find
getElementsByTagName ()//By label name
Getelementsbyname ()//through the value of the element's Name property
getElementById ()//via element ID, uniqueness
------------------------------------------------------------------------------
19. Explain the principles of JSONP, and why not real Ajax?
The method of submitting HTTP requests to different domains using the method of creating <script> nodes in a page is called JSONP, which solves the problem of submitting Ajax requests across domains. The working principle of JSONP is as follows:
Suppose you submit a GET request to http://example2.com/getinfo.php on the http://example1.com/index.php page, we can put the following JavaScript code in the http:// example1.com/index.php this page to implement:
var elescript= document.createelement ("script");
Elescript.type = "Text/javascript";
ELESCRIPT.SRC = "http://example2.com/getinfo.php";
document.getElementsByTagName ("Head") [0].appendchild (Elescript);
When a GET request returns from http://example2.com/getinfo.php, a section of JavaScript code can be returned, which is automatically executed and can be used to invoke the http://example1.com/ Index.php a callback function in the page.
The basic principle of JSONP is to dynamically add a <script> tag, and the SRC attribute of the script tag is not cross-domain. In this way, this cross-domain approach has nothing to do with the Ajax XMLHttpRequest protocol.
------------------------------------------------------------------------------
20.javascript of local objects, built-in objects, and host objects?
1, internal objects The internal objects in JS include array, Boolean, Date, Function, Global, Math, Number, object, REGEXP, string, and various error class objects, including errors, Evalerror, Rangeerror, Referenceerror, SyntaxError and TypeError. The two objects, global and math, are also referred to as "built-in objects", which are created when the script is initialized and do not have to instantiate the two objects. |
|
|
2. Host Object The host object is the object provided by the environment that executes the JS script. For JS embedded in the Web page, the host object is the object provided by the browser, so it is also called the browser object, such as IE, Firefox and other browsers to provide the object. The host objects provided by different browsers may be different, even if the objects provided are the same, and they are implemented differently. This can create browser compatibility issues and increase development difficulty. There are many browser objects, such as window and document, and so on. |
|
3. Custom Objects
As the name suggests, is the developer's own definition of the object. JS allows the use of custom objects, so that JS applications and functions are expanded
------------------------------------------------------------------------------
What is the difference between 21.document load and document ready?
$ (document). Load ();
When the Web page and its accompanying resource files, such as css,scripts, pictures, etc., execute this method after loading.
Often used to detect whether a page (and its accompanying resources) is loaded.
$ (document). Ready ();
This method is triggered when the page DOM object is loaded and the Web browser is able to run JS. If you want to execute JS as soon as possible, you can use this method. [The JS code in the Script tab of the header of the HTML that is not in ready () will be performed earlier Than Ready ()]
------------------------------------------------------------------------------
22. What is the difference between "= =" and "= ="?
=: One is to determine whether the value is equal
= =: One is to determine whether the value and type are exactly equal
------------------------------------------------------------------------------
23.javascript's homology strategy?
The homologous strategy simply means that a script can only read the properties of Windows and documents from the same source, where the same source refers to the combination of host name, protocol, and port number;
------------------------------------------------------------------------------
24. Write an array to weight the method?
First Type: 1. Build a new array to store the results
2.for