Html5+js Test Questions

Source: Internet
Author: User

Html5+js Test Questions

==============================================
1. Talk about your understanding of JS closures:

  

Closures are a relatively abstract concept, especially for JS novices. The explanation in the book is rather obscure, and it is the same for me.

But he is also the ability to improve the JS can not be bypassed, almost every interview must ask questions, because in the answer. The depth of your answer, the understanding of terminology and the description of how the JS internal interpreter works can be seen in the actual level of your JS. Even if you don't answer correctly, You can also have an assessment of your level by the examiner. So let me say my understanding of the closure in JS.

Closures are the characteristics of many languages, in JS, closures are mainly related to JS a few other features: scope chain , Garbage (memory) recycling mechanism , function nesting , and so on.

Prior to understanding closures. It is better to understand the meaning of the scope chain , in short, the scope chain is what the function creates at the time of definition, to find an index of the value of the variable used, and his internal rule is to put the local variables of the function itself first, Put the variables in their parent functions next, put the variables in the higher-level function later, and so on until the global object. When the function needs to query the value of a variable, the JS interpreter will go to the scope chain to find, from the first local variable to find, if not found the corresponding variable, To the next level of the chain, once the variable is found, it will no longer continue. If the required variable is not found at the end, the interpreter returns undefined.

Understanding the scope chain, we look at the JS memory recovery mechanism , in general, a function at the beginning of execution, it will be defined in the variable memory space to save, in case of the subsequent statements to use, wait until the function is finished to return, These variables are considered useless. The corresponding memory space is also recycled. The next time the function is executed, all the variables return to their original state and are re-assigned. But if another function is nested inside the function, And this function is likely to be called externally. And this internal function uses some variables of the external function. This memory-recycling mechanism can cause problems. If an intrinsic function is called directly after the external function returns, the Then the intrinsic function cannot read the value of the variable in the external function that he needs. So the JS interpreter will automatically save the function and the variables he or she may use, including the local variables and the variables (free variables) of the parent and ancestor-level functions, when it encounters the function definition. That is, to build a closure, These variables will not be reclaimed by the memory collector, but only if the internal function is not possible to be called (for example, if it is deleted, or if there is no pointer), the closure will be destroyed, and no one of the closure references will be recycled when the next memory recycle starts.

In other words, with closures, nested function structures work, which is what we expect. Then, closures have some features that are often difficult for programmers to understand.

Take a look at the following section of code.

var result=[];function foo () {    var i= 0;    for (; i<3;i=i+1) {        result[i]=function () {            alert (i)        }    }};foo (); result[0] ();//3result[1] ();// 3RESULT[2] (); 3

In this code, the programmer wants the variable i in the Foo function to be used by the inner loop function, and can get their index separately, and in fact, only the value that the variable is last reserved, that is. The free variable that is recorded in the closure is just a reference to the variable, not the value of the variable, when the variable is changed , the value of the variable obtained in the closure will also be changed.

One way to do this is to have the inner function execute as soon as the loop is created, capture the current index value, and then record it in one of its own local variables. Then, using the return function method, rewrite the intrinsic function, let the next call, return the value of the local variable, the improved code:

var result=[];function foo () {    var i= 0;    for (; i<3;i=i+1) {        result[i]= (function (j) {            return function () {                alert (j);            };        }) (i);}    ; Foo (); result[0] (); 0RESULT[1] (); 1RESULT[2] (); 2

I'll explain here again. Here are 2 additional techniques that are called immediately by anonymous functions and return functions. It is also a difficult part for beginners to understand.

-----------------------------------------------------------
2. Talk about your understanding of cookies and their pros and cons:
What are the 3.html5 browser local storage?
What is the difference between 4.web storage and cookies?
The difference between 5.cookie and session:
The difference between 6.display:none and Visibility:hidden?
Similarities and differences of 7.position:absolute and float properties
8. Describe the Box-sizing property?
What are the 9.CSS selectors? Which properties can be inherited? How is the priority algorithm calculated? CSS3 What are the new pseudo-classes?
The value of 10.position, relative and absolute respectively, relative to who is positioned?
What are the new features of 11.CSS3?
What is the difference between 12.XML and JSON?
13. Tell me about your understanding of the semantic label?
14. What are the common compatibility issues with web design and how to solve them?
15. Explain the float and how it works? Tips for clearing floating
16. Problems and solutions caused by floating elements?
17.DOM operations-How to add, remove, move, copy, create, and find nodes
What are the new features and elements removed from 18.HTML5? How do I handle browser compatibility issues with HTML5 new tags? How do I differentiate between HTML and HTML5?
What are the advantages and disadvantages of 19.iframe?
20. How can I achieve communication between multiple tabs in the browser?
21. Please say three ways to reduce page load time
The difference between 22.documen.write and innerHTML
23.sql Injection principle
24.XSS Principle and prevention
What is the difference between 25.XSS and CSRF?
26.CSRF of Defense
27.Flash, the advantages and disadvantages of Ajax, in the use of how to choose?
What is the difference between 28.GET and post and when to use post?
29.HTTP Status Code
30. Talk about optimization of Web page performance

Html5+js Test Questions

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.