Web Front-end interview 01 and web interview 01

Source: Internet
Author: User

Web Front-end interview 01 and web interview 01
1 -- what is a DOM event handler?
What is DOM first? Dom is an API for HTML documents. What is an event stream? Event streams are divided into event bubbles (IE event streams) and event capturing. Event bubbling is to receive events from the most specific elements, and then step by step. Event capture is to receive events from less specific elements, step by step, and finally to the most specific elements.
DOM Event Handlers are classified into DOM0 and DOM2 levels. DOM0 has the advantage of being simple and cross-browser. It assigns a function to the handler attribute of an event. Example: btn. onlick = function (){...}; DOM2-level events define two methods for processing specified and deleted event handlers. AddEventListener () and removeEventListener (). They all receive three parameters: the name of the event to be processed, the function used as the event handler, And the Boolean value. If the Boolean value is true, the event handler is called in the capture phase. If the Boolean value is false, the event handler is called in the bubble. Note: Remove "on" from the event name ". Events added through addEventListener () can only be deleted by removeEventListener. IE is compatible. You can use attachEvent () to add events and detachEvent () to delete events. Receives two parameters: the name and function of the event handler. Note: Add "on" to the event name ".
2 -- What if two events are bound to an element at the same time?
You can add multiple events to an element at level 0 and level 2 of Dom. Each event at level 0 of Dom supports only one event handler. If you bind the same event, then, the next event will overwrite the previous event function. Multiple event handlers can be added at the Dom2 level, which are triggered in the order of addition.
3 -- what is the difference between call and apply?
First, you must understand the functions of call and apply. Both call and apply exist to change the context of a function runtime. In other words, they are used to change the point of this in the function body. Because JavaScript functions have the following concepts: "definition context", "RunTime context", and "context can be changed. Call and apply dynamically change this. When an object does not have a certain method, but other methods are available, we can use call or apply to operate other objects. The only difference between them is that the call needs to pass the parameters in order, while the apply operation places the parameters in the array.
4 -- what is a closure? (This is really important !)
Closures have three features: 1. nested functions; 2. Internal functions can reference external parameters and variables; 3. Parameters and variables are not recycled by the garbage collection mechanism. A closure is a function that has the right to access the variables in another function scope. The most common way to create a closure is to create another function in one function and access the local variables of the function through another function. A disadvantage of using closures is that local variables can reside in the memory to avoid using global variables. Global variables can be called in each module, which is disastrous. (Private, encapsulated local variables are recommended .) Generally, after the function is executed, the partial activity object is destroyed, and only the global scope is saved in the memory. But the closure is different!
A more thorough explanation: the so-called "closure" refers to defining another function in the constructor as the method function of the target object, the method function of this object references the temporary variables in the outer function body. This allows the target object to indirectly retain the temporary variable value used by the original constructor as long as it can maintain its method throughout the lifetime. Although the call to the initial constructor has ended, the name of the Temporary Variable disappears, but the value of the variable can always be referenced in the method of the target object, this value can only be accessed in this way. Even if the same constructor is called again, only new objects and methods are generated. The new temporary variables only correspond to new values, which are independent of those called last time.
By the way, immediately execute the relationship between the function and the closure: the immediate execution function can work with the closure to save the state. Like passing parameters through common functions, parameters can also be passed when a function is executed immediately. If another function is defined within the function, and the function can reference external variables and parameters (closures), we can use the immediate execution function to lock the variable storage status.
A round of interview is basically the focus of these questions, similar to the common interview questions on the Internet. At that time, I was shopping, and it was very noisy around me. After I had barely heard the interviewer's questions, I replied with a strong voice and did not know whether the interviewer's ears had been heard. The rest is about the projects you have done, some js special effects you have written, and the level of HTML5 and CSS3. It lasted about 20 minutes, and the whole process was very high.
I did not expect to receive a call from two rounds of interviews one day. This time, my environment was very quiet, so the entire interview process was "dull ". At the same time, I received a call. This interview question is very basic. First of all, I asked what I was interested in. I told him that I was about software development and I didn't know much about hardware. He asked me what language I usually use. I basically said it was JavaScript and I learned c in my freshman year. So he asked me, in C language, the function to open the file, I said open (), the correct should be fopen (). Then he asked me how to achieve quick sorting. I answered the question and asked about the file management mechanism of the operating system. I was so stupid at the time. I said I was not very clear, so he said, what about the network, I said that this school has learned a computer network course, so he simply said that the http protocol, I said tcp/tp? He said no. Okay. I'm stupid. I just vaguely remember three handshakes.
1-http protocol:
It is a communication protocol that allows HTML documents to be transmitted from a web server to a browser on the client. It is an application layer protocol that is hosted on TCP and consists of requests and responses, is a standard client server model.
2-difference between get and post
Get is used to retrieve data, and post is used to transmit data. Difference: get transmits data in the URL, with low capacity, poor security, and cache. post transmits data in the http content container, which features high capacity, better security, and no cache.
3-What is cookie?
Cookies are used to store information on pages. They share the same set of cookies under the same domain name. The number is limited, generally about 50, and the size is limited (4-10 k ); in addition, an expires value is specified when an expiration time is generated. This is the lifecycle of an expires instance.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.