DOM

1. Required test: Event delegation

Incorrect version (but may pass)

Ul. AddEventListener (' click ', function (e) {if (e. arget. TagName. ToLowerCase () = = = 'li') {fn () / / execute a function}}) bug is, If the user clicks on a span in Li, fn cannot be triggered, which is obviously not true.Copy the code

premium

function delegate(element, eventType, selector, fn) { element.addEventListener(eventType, e => { let el = e.target while (! el.matches(selector)) { if (element === el) { el = null break } el = el.parentNode } el && fn.call(el, e, El)}) return element} the idea is to click on a span and recursively iterate over the ancestor elements of the span to see if there is a LI in ul.Copy the code

2. Write a dragable div with the mouse event

Reference code: jsbin.com/munuzureya/…

HTTP

3. What do HTTP status codes know? What do they mean?

2xx indicates success

3xx indicates that further operations are required

4xx indicates an error in the browser

5xx indicates a server error

For full reference www.runoob.com/http/http-s…

3. What are the types of HTTP caches?

Understand the similarities and differences between ETag, CacheControl, and Expires in detail

Reference imweb. IO/topic / 5795 d…

Answer key points: ETag determines whether to send a file’s content by comparing the browser and server resource’s signature values (such as MD5). If so, only 304 (Not Modified) Expires is set. However, if the user’s local time is out of order, Possible problems CacheControl: max-age=3600 Specifies the expiration period. This parameter is independent of the local time.

4. What’s the difference between GET and POST

Wrong answer, but pass the interview

GET is harmless when the browser falls back, while POST resubmits the request.

The URL generated by GET can be added to favorites, but POST cannot.

GET requests are actively cached by browsers, whereas POST requests are not, unless set manually.

GET requests can only be url encoded, while POST supports multiple encoding methods.

GET request parameters are retained in browser history, while parameters in POST are not.

GET requests pass parameters in the URL with length limits, whereas POST does not.

GET accepts only ASCII characters for the data type of the argument, while POST has no restrictions.

GET is less secure than POST because parameters are exposed directly to the URL and therefore cannot be used to pass sensitive information.

The GET argument is passed through the URL, and the POST is placed in the Request body.

Positive solution

Just one difference: semantics — GET for getting resources, POST for submitting resources.

Want to pack to force zhuanlan.zhihu.com/p/22536382 please reference

5. Cookie VS LocalStorage VS SessionStorage VS Session

Cookie VS LocalStorage

The main difference is that cookies are sent to the server, while LocalStorage is not

Cookie usually has a maximum size of 4K, and LocalStorage can use 5Mb or even 10Mb (depending on browser)

LocalStorage VS SessionStorage

LocalStorage generally does not expire automatically (unless manually cleared by the user), whereas SessionStorage expires at the end of a reply (e.g. closing a browser)

Cookie VS Session

Cookies are stored in the browser file, Session is stored in the server file

The Session implementation is based on cookies, by storing the SessionID in the Cookie