Recently, I went to a unicorn company for a round of interview. I thought that I could do well with years of rich project accumulation, but I was “educated” by the interviewer. I was really ashamed.

Was a few front-end knowledge points in a row asked meng force, come back after a good tutorial. Here are some thoughts on interview questions:

1. Can a variable defined by const not be assigned a value and point to where?

A: Let may not be assigned, and const may not be assigned. Missing initializer in const declaration is Missing. Let has no variable promotion and must be declared before it can be used. Const defines a regular variable, not because its value cannot be changed, but because the data stored at the memory address to which the variable points cannot be changed. Const an object or array that points to a memory address holds only a pointer to actual data. Const guarantees that the pointer is fixed, but has no control over whether the data structure it points to is mutable.

2. What is the difference between pNG8 and PNG24?

A: PNG file formats are divided into PNG-24 and PNG-8. The biggest difference is that PNG-24 uses 24 bits to store a pixel value, which is true color, while PNG-8 uses 8-bit index value to index a color in the palette. Because the maximum limit of an index value is 2 to the power of 8, i.e. 128, the maximum number of colors in the palette is 128. So this file format is also called PnG-8128 imitation color. I only answered with different precision, pNG24 is larger, and the interviewer added how much larger? Is there a pattern? When I came back, I actually tested the size of the same image pNG24 was 434.5KB, and the size of pNG8 was 124KB, nearly 4 times the size difference.

2. I know that object.defineProperty is used to listen, but I forgot the details. var a = {} Object.defineProperty(a, ‘name’, { set: function(newValue){ console.log(`newValue == ${newValue}`) }, get: function(){ return 2 } }) console.log(a.name)

4. What is the difference between HTTP and HTTPS?

5. Principle of Cross-domain CORS (actually a whitelist)

6. Does it matter if the cookie is stored too much? What’s the difference between cookie and localStorage?

Cookie is inserted in the request header, take PHP language for example, when requesting a page, cookie will be transmitted to the server through HTTP protocol, this is also through $_COOKIE can obtain the remote client’s cookie principle. So if the Cookie is too large, the entire HTTP header is stretched.

Difference: Cookie data is always carried (even if it is not needed) in same-origin HTTP requests, i.e. cookies are passed back and forth between the browser and the server. However, sessionStorage and localStorage do not automatically send data to the server and only store data locally. Cookie data also has the concept of path, which can restrict cookies to a specific path. The storage size limit is also different, cookie data cannot exceed 4K, and because cookies are carried with each HTTP request, cookies are only suitable for storing very small data, such as session identifiers. SessionStorage and localStorage, while also limited in size, are much larger than cookies, reaching 5M or more. SessionStorage: only valid before the current browser window closes, naturally it is not likely to last; LocalStorage: always valid, saved even when the window or browser is closed and therefore used as persistent data; Cookies only remain valid until the set cookie expiration time, even if the window or browser is closed. Different scopes, sessionStorage is not shared in different browser Windows, even on the same page; LocalStorage is shared in all origin Windows; Cookies are also shared across all the same origin Windows. The Web Storage supports the event notification mechanism to notify listeners of data updates. The API interface of Web Storage is easier to use.

I have been doing business for the past two years, and I just do what needs come along. I seldom study its specific principles. The technical interviewer told me to go deep, otherwise in 5 or 7 years without their own technical barriers, they can not be compared with young people who have worked for 2 or 3 years. Ashamed, want to pay more attention to the thing of principle respect later.