Summary of interview questions (PS: just those interview questions I encountered, not classic interview questions)

First, the difference between class and structure, respectively, what are the applications. (Reference: https://blog.csdn.net/yikeshu19900128/article/details/40400479 )

1) The class is a reference type, the data is stored on the heap, and the pointed address is stored on the stack. Structures are value types, and data is stored on the stack.

2) Classes can inherit, can inherit another class or interface, and can also be inherited. Structs cannot inherit, cannot inherit from another struct or class, and cannot be inherited, but interfaces can be inherited.

3) Classes can be initialized at declaration time, structs cannot be initialized at declaration time.

4) In a class, once we write the parameterized constructor, the default constructor does not exist. When we want to call a constructor with no parameters to initialize an object, we have to write another constructor without parameters ourselves. But in a structure, there is always a default constructor with no parameters, and this constructor is irreplaceable and cannot be overridden or overridden. In a structure, we can only write a constructor with parameters, not constructor with no arguments

5) Destructor: A class has a destructor, but a struct does not have a destructor

6) Keywords: keywords that can be used in classes but restricted in structures are: abstract, sealed, protected; Static keywords can be used in front of the class name to declare static classes, but cannot be used in front of struct, no there is a static structure

7) Classes use new to instantiate objects and allocate memory, and need to use new to return the address and allocate space, while structures are initialized with new, and structures are value types, and memory has been allocated when they are declared.

Analysis of applicable occasions for structures and classes: (Reference: https://blog.csdn.net/Iqingshuifurong/article/details/53129536 )

  1. When the stack space is very limited and there are a large number of logical objects, it is better to create a class than to create a structure;

  2. For lightweight objects such as points, rectangles, and colors, if you want to declare an array containing many color objects, the CLR needs to allocate memory for each object. In this case, the cost of using the structure is lower;

  3. Classes are the best choice when representing abstraction and multi-level object hierarchies, because structs do not support inheritance.

  4. In most cases, the target type only contains some data, or mainly data.

2. What is the difference between using sql statement directly and querying with stored procedure in the project (reference: https://www.cnblogs.com/binyue/p/6442310.html )

3. What are the ways to optimize the website? (Explain from both the server and the client side) (Reference: https://www.zhihu.com/question/21658448 )

[If you know this, I hope you can share your answer in the comment area, thank you]

There are many ways of front-end optimization, which can be roughly divided into two categories according to the granularity. The first category is page-level optimization, such as the number of HTTP requests, non-blocking loading of scripts, and location optimization of inline scripts; the second category is code Level optimization, such as DOM manipulation optimization in Javascript, CSS selector optimization, image optimization, and HTML structure optimization, etc. (Author: Sidi Link: https://www.zhihu.com/question/21658448/answer/18903129 Source: Zhihu)
 
 
4. How to avoid repeated submission after clicking the button? [Write all the methods you can think of] (Reference: https://www.cnblogs.com/wuyx/p/6118484.html )
1) After the button is clicked to submit, make the button unavailable, and restore it after the operation is completed.
2) Set a variable to record the number of button clicks. If it is 0 when it is clicked, perform the submit operation, otherwise return.
3) After clicking the button to submit, a dynamic effect of "Waiting..." can be added to the page. The page where the button is located cannot be clicked when the operation is not completed. After performing the operation, hide the dynamic effect and restore the page.
4) Use a cookie to save the time of the last click and submit, compare the time interval between the two times, and filter out the second submission if you think the interval is too short.
5) There are also methods in the link  https://www.cnblogs.com/wuyx/p/6118484.html  [Additional welcome]
 
5. What are the basic data types in JavaScript? (Reference: https://www.cnblogs.com/mybwhy/p/7245234.html?utm_source=itdadao&utm_medium=referral )
1) Undefined type: The Undefined type has only one value, which is undefined. The typeof operator on both uninitialized and undeclared variables returns undefined.
2) Null type: Null type is the second data type with only one value, namely null. A null value represents a null pointer object, so the typeof operator returns "object" when it detects a null value.
3) Boolean type: The Boolean type has two literal values: true and false. true is not necessarily equal to 1, and false is not necessarily equal to 0. Note that true and false are case-sensitive, which means that neither True nor False (and other mixed case forms) are Boolean values, just identifiers.
4) Number type:
5) String type: Numerical values, Boolean values, objects, and string values ​​all have the toString() method, but null and undefined values ​​do not.
6) Object type: Object type is the basis of all other instances in javascript.
Reference question:
<script>
 
  var a='12.3';//string type
 
  var b=12.6;//number type
 
  var c=a+b;//c is string type
 
  alert(c);//What is the result? ====> result is 12.312.6
 
</script>
 
        When do I get the result 24? When did you get 25? [Rounding in js, reference: http://www.jquerycn.cn/a_11512 ]
<script type="text/javascript">
    var a = '12.3';
    a = parseInt(a);//a=12
    var b = 12.6;
    var c = a + b;//c=24.6
    alert(typeof (c));//number类型
    alert(parseInt(c));//24
</script>
<script type="text/javascript">
    var a = '12.3';
    a = parseFloat(a);
    var b = 12.6;
    var c = a + b;
    alert(c); // 24.9 
    alert( typeof (c)); // number type 
    alert(c.toFixed( 0 )); // 25 rounding function tofixed(n) in js, n is the decimal to keep digits. n is 0~20, when n exceeds 20, js will make an error. 
</script>

 

 
 
 



 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324648873&siteId=291194637
Recommended