Interview questions JavaScript03【2021-10】

1. var f = foo||bar , what does this line of code mean? Why do you write like this?

        or short circuit       

        If foo is false, 0, null, undefined, empty string, take the value of bar

        This is a quick way to assign

2. Briefly describe your understanding of toString and valueOf

        toString is to convert any object, basic type, and string into a string, and others will rewrite toString

        valueof returns the original value of the object itself

3. Describe the running process of the new operator

        Implementation principle of new operator_izwell's Blog-CSDN Blog_Principle of new operator

        Create a new object O, point the property of O __proto__to the prototype property of the constructorprototype

        Bind the execution context of the constructor to O, and execute the constructor to get the return value S

        If S is an object, the new operator returns the S object

        If S is not an object, the new operator returns O

4. How to implement Javascript prototype inheritance, the difference between prototype and __proto__ of the prototype chain

        Introduction to javascript prototypal inheritance_360问题

        https://www.jb51.net/article/81766.htm

5. What are the methods of js lazy loading?

        Several ways of JS lazy loading_meijory's blog-CSDN blog_What are the ways of js lazy loading?

        js lazy loading, that is, wait until the page is loaded before loading the js file, which helps to improve the page loading speed

        The main methods are defer attribute, async attribute, dynamically create DOM method, jQuery getScript method, setTimeout, and put the js file at the bottom of the file

        defer:

                Set the deger attribute in <script>, the browser will download it immediately and delay execution, which is suitable for external script files of HTML4.

        async:

                Set the async attribute in <script> to prevent the page from waiting for the script to be downloaded and executed, thereby loading other content on the page asynchronously, suitable for external script files

6. Which Javascript libraries have you used, and which Javascript plug-ins have you used?

        jQuery,moment、axios、awesome、echarts、validator、css-modal、

7. Briefly introduce the front-end frameworks and differences you know

        Comparison of the three mainstream web front-end frameworks - Morality first - Blog Park

        Compared to other frameworks — Vue.js

        Angular、React、Vue

        Similarities: Both are progressive frameworks , which can realize more powerful functions by supporting different tools; both are component-based development , which can well solve the problems of division of labor and maintenance; both are one-way data flow

        Vue features: lightweight, two-way data binding, instructions, plug-ins, official documents are clear and easy to learn

        React features: adopt life paradigm, simulate DOM, efficient, flexible, fast, cross-browser compatible

       Angular features: the module is powerful, can be customized and specified, and can be introduced into the backend (embedding, injection, testing)

8. What are the HTTP status codes? What does represent respectively mean?

        HTTP learning - what are the common HTTP status codes?

        1xx provisional response

        2xx success

        3xx redirect

        4xx Client Request Error

        5xx server errors

        Commonly used status codes are as follows:

                200 OK The request was successful

                301 Resource moved, the requested resource automatically goes to the new URL, and the browser automatically jumps to the new URL

                304 The server resource is consistent with the client's last request and does not need to be retransmitted 

                400 Bad Request The client sends a bad request

                403 Not authorized

                404 Not Found page missing, resource not found

                500 internal server error

                501 An internal server error prevented the request from being serviced

9. Please talk about the debugging tools you have used in the front-end development process

        Common front-end debugging tools - short book

        F12 (Element, Console, Source, Network, Performance, Memory, Applications, Security, Benchmark)

        breakpoint

        postman

10. Talk about the difference between cookie and session

        1-cookie data is stored in the client browser, session data is stored on the server

        2-cookie is insecure and can be cheated, session is safe

        3-session will be saved on the server for a certain period of time. If the access is too large, it will take up server performance. At this time, cookies should be used

        4- The data saved by a single cookie cannot exceed 4k, and most browsers limit a site to save up to 20 cookies

        5-cookie can only save ascll string, session can access any type of data

        6-The validity period of the cookie is longer (can be set), and the session is invalid when the browser is closed

        7-cookie supports cross-domain access, session does not support cross-domain access

        8-cookie needs browser support, and can be set to be valid for this window and sub-windows, or set to be valid for all browser windows; session can only be set to be valid for this window and sub-windows.

11. What will the following code output? Why?

var foo = 1;
function test(){
 console.log(foo);
 var foo = 2;
 console.log(foo);
}
test();

undefined -- because the variable is promoted; if it is let, it becomes a dead zone

2 -- The local variable foo is defined

12. What will the following code output? Why?

var User = {
 count: 1, 
 getCount: function() {
 return this.count;
 }
};
console.log(User.getCount()); 
var func = User.getCount;console.log(func());

1

undefined --this points to window, and an error will be reported in strict mode

Thirteen, look at the following code, give the output result. How to make the code output 1 2 3?

for(var i=1;i<=3;i++){
 setTimeout(function(){
 console.log(i); 
 },0); 
};

444

If you want to output 123, you need to replace var with let, which forms a block-level scope/closure

Guess you like

Origin blog.csdn.net/weixin_43961652/article/details/121219452