Home > Web Front-end > JS Tutorial > The ten latest front-end interview questions in 2018

The ten latest front-end interview questions in 2018

php中世界最好的语言
Release: 2020-09-01 15:50:43
Original
3096 people have browsed it

This time we bring you the latest front-end interview questions in 2018. We know that interviews are an essential part of front-end work. This time, the common front-end interview questions are sorted and summarized to help you get through the front-end interview. Big trouble. Let’s take a look.

[Related recommendations: Front-end interview questions (2020)]

1. Please describe the difference between cookies, sessionStorage and localStorage .

Software programming hopes to store some useful data persistently through some means. For network programming, this task is generally handed over to the server-side database or browser-side cookies. With the emergence of HTML5, web development has two options: Web Storage and Web SQL Database.

WebStorage comes in two forms: LocalStorage (local storage) and sessionStorage (session storage). Both methods allow developers to operate with key-value pairs set by js and read them when reloading different pages. This is similar to cookies.

1: Cookie data is always carried in the http request from the same origin (even if it is not needed), that is, the cookie is passed back and forth between the browser and the server. SessionStorage and localStorage do not automatically send data to the server, but only save it locally. Cookie data also has the concept of path, which can restrict cookies to only belong to a certain path.

2: The storage size limit is also different. Cookie data cannot exceed 4k. At the same time, because each http request carries a cookie, cookies are only suitable for saving very small data, such as session identifiers. Although sessionStorage and localStorage also have storage size limits, they are much larger than cookies and can reach 5M or more.

3: The data validity period is different. sessionStorage: is only valid until the current browser window is closed, and naturally cannot be persisted; localStorage: is always valid, and is saved even when the window or browser is closed, so it is used as a persistent Data; cookies are only valid until the set cookie expiration time, even if the window or browser is closed.

4: Different scopes, sessionStorage is not shared in different browser windows, even on the same page; localStorage is shared in all homologous windows; cookies are also shared in all homologous windows. shared.

5: Web Storage supports event notification mechanism, which can send data update notifications to listeners.

6: Web Storage’s api interface is more convenient to use.

2. Please explain the difference between <script>, <script async> and <script defer></strong>. </p> <p>The main way to insert <a href="http://www.php.cn/wiki/48.html" target="_blank">javascript</a> code into an html page is through the script tag. There are two forms, the first is to insert js code directly between script tags, and the second is to introduce external js files through the src attribute. Since the interpreter will block the rendering of the rest of the page during the parsing and execution of js code, pages with a large amount of js code will cause long periods of blank space and delays in the browser. In order to avoid this problem, it is recommended to put all js references in before the </body> tag. </p> <p>The script tag has two attributes, defer and async, so the use of the script tag is divided into three situations: </p> <p>1.<script src="example.js">< /script><br>Without defer or async attributes, the browser will immediately load and execute the corresponding script. That is to say, before rendering the document after the script tag, it does not wait for the subsequently loaded document elements, and starts loading and executing them as soon as it is read. This will block the loading of subsequent documents; </p> <p>2.<script async src ="example.js"></script>
With the async attribute, it means that the loading and rendering of subsequent documents and the loading and execution of js scripts are performed in parallel, that is, asynchronous execution;

3.
With the defer attribute, the process of loading subsequent documents and the loading of js scripts (only loading but not execution at this time) are carried out in parallel (Asynchronous), the execution of the js script needs to wait until all elements of the document are parsed and before the DOMContentLoaded event is triggered.

3. Why is it usually recommended to place CSS between and JS

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template