[Front-end interview] Basic knowledge (1)

Note: The combination of difficulty and importance is marked with *

What is the relationship between Java and JavaScript? *

Answer: Theoretically speaking, it has nothing to do with it, nor is it produced by the same company. At that time when js was developed, java was hot, so the senior management wanted to have some relationship with java, so they named it javaScript. The content of the two is also different.

JS is an interpreted language, which can be interpreted and executed at the same time, while Java needs to be compiled first and then executed.

Generally speaking, java has stricter syntax than js and has many more functions.

What is the difference between deep copy and shallow copy in js? ***

For simple data types, such as number, string

When I set a = 1, I assign a to b. When b changes, it will not have any impact on a.

But when I set an object type or array type a = [1,2,3], then if I assign a to b, what b actually receives is the address of a, so I operate the array of b, such as deleting the last An element makes b = [1,2], and a will also change at the same time, because b is just an address of a, and operating b actually still operates a.

So the operation of directly assigning a to b is a shallow copy, but if the value is only copied, the address changes, and a does not change when b is changed, then it is a deep copy.

Answer: Shallow copy only copies the address of the object or array. Deep copy changes the address of the original object and only assigns the value. Even if the value is changed, the original data will not be affected.

Generally, I will re-create an empty array and traverse the assignment to make a deep copy.

For objects, I will use the JSON.parse(JSON.stringify(obj)) method to deep copy it.

JSON.stringify(obj) converts the obj object into a json string. JSON.parse() converts the json string in brackets into an object, so this function is to convert it into a json string and then convert it back. , to achieve the effect of a deep copy, the above sentence can be said as follows:

For objects, I will use JSON.stringify to convert it into a json string, and then parse the json string into an object to achieve the effect of deep copying.

The difference between arrow functions and ordinary functions***

What is an arrow function?

The arrow function refers to the function of the following structure

() => {}

The parameters in parentheses are the parameters of this function, and the curly braces represent the execution content of this function. For example, I implement a function that prints the received value:

(value)=>{
    console.log(value);
}

Why use arrow functions?

Because arrow functions can sometimes replace simple function types and simplify some codes, some places need to receive a function, but the function of this function is not complicated. It may only be one or two sentences, which can be represented by an arrow function. Arrow functions are anonymous Functions cannot be reused.

For example, the most commonly used timer function, the most basic usage of the timer setTimeout has two parameters. The first parameter is to receive a function, and the second parameter is a time. It can run the received function after the specified time. The function. Usually we can use arrow functions here, for example, to implement a function that prints a sentence after three seconds:

setTimeout(()=>{
    console.log('一句话...');
},3000)

Answer: The arrow function does not have its own this point. Its this point is always in its own scope. However, the this of an ordinary function can be changed, that is, whoever calls it will have its this point.

The arrow function is an anonymous function. It cannot be reused and has no prototype chain.

How to understand the prototype chain****

Simple understanding of the prototype chain in an easy-to-understand way

The easy-to-understand understanding of the prototype chain is that it can be imagined as a chain, connected to each other to form a whole chain!

The prototype chain is the link between the instance and the prototype. Each function has a prototype attribute. This prototype attribute is our prototype object. We take the instance object created by this function through the new constructor. This instance object itself will have a pointer (_proto_) pointing to the prototype of its constructor. Object! In this way, the constructor and the instance object are connected together through (_proto_) to form a chain.

What happens when you enter a URL in your browser to access a website? *****

1. The URL/domain name you entered is sent to the DNS server, and the corresponding IP address is obtained through the DNS server.

DNS is a domain name service and can be understood as a public database.

Usually, if you want to access a website, you need to access the IP, which is similar to 192.168.0.1

The URL we enter is to access the database through DNS to find the IP corresponding to this URL.

2. After getting the IP, we start to initiate a TCP connection (three-way handshake) to the target IP

TCP related knowledge is under construction and has not been finished yet

3. After confirming that TCP is successful, the browser begins to formally send a request for a page.

4. After receiving the request, the server sends the page to the browser

5. The browser starts to build the DOM tree through the received pages (html and so on), that is, rendering the page.

6. If you want to close it, use TCP to close the connection to the server (wave your hands four times)

Guess you like

Origin blog.csdn.net/FishWooden/article/details/129039048