Daying Internship Front-end Written Exam 2023

【Multiple choice】8

【Questions】1

【Programming questions】2

【Multiple choice】

1. Which of the following options belong to JavaScript macro tasks? (CD)

A.promise

B.async/await

C. Main code block

D.setTimeOut

Macro tasks: tasks initiated by the browser

Micro tasks: tasks initiated by the js engine itself

1. js macro tasks include:

2. The following description of the arrow function in Javascript is correct (CD)

A. You can use the built-in arguments object of the function to get the function

B. You can use the yield command

C. When using => to define a function, inherit the current context this keyword

D. The constructor cannot be used (the new command cannot be used, otherwise an error will be thrown)

About arrow functions:

1. It cannot be used as a constructor, because it does not use its own this, arguments, etc.

2. The yield command cannot be used

3. Do not bind this: no own this object, the internal this is the this object in the upper scope at the time of definition (the internal this of the arrow function is fixed, and the ordinary function is variable)

3. What basic data types does Javascript have? (ABC)

A.Boolean

B.Null

C.Object

D.Function

1、String

2、Number

3、Boolean

4、Null

5、Undefined

4. In JavaScript, the DOM event listener is registered to the parent element. After the child element is clicked, will the click event be triggered by the event listener callback of the parent element? (A)

A. Kai

B. will not

bubble

5. Which methods of the array are called by JavaScript without modifying the array? (ABD)

A.map

B.forEach

C.sort

D.concat

A.arr.map((item)=>{ return xx}) returns a new array created

B.arr.forEach((item)=>{the array will not be modified if no change is made here}) has no return value meaning

C. Sort, will modify

D. Merge arrays, return the merged copy of the two arrays, and will not change the two original arrays

6. In the following cases, js may have a memory leak (AB)

A. The timer is not cleared

B. When the DOM is emptied, there are still references

C. Using arrow functions

D. Frequent operation of DOM

1. Unexpected global variables

2. The timer is not cleared

3. References to DOM elements are not cleaned up

7. [Single choice] Which of the following methods can directly obtain the DOM node of a div? ©

A.document.getElementByClass(“two”)

B.document.getByTagName(“three”)

C.document.getElementById(“one”)

Get by ID (getElementById)
by name attribute (getElementsByName)
by tag name (getElementsByTagName)
by class name (getElementsByClassName) by a
selector to get an element (querySelector)
by a selector to get a group of elements (querySelectorAll)
to get html method (document. documentElement)
to get the body method (document.body)

8. Which of the following are restrictions of JavaScript strict mode? (ACD)

A. Undeclared variables cannot be used

B. Assigning a value to NaN will throw an exception

C. The parameter name of the function must be unique

D. The this of the hexadecimal custom function points to window

1. Prohibit non-standard global variables (unused var)
2. Prohibit the use of with statement
3. Prohibit the use of eval
4. Prohibit the this keyword from pointing to the global object
5. Prohibit traversing the call stack inside the function
6. Prohibit deleting variables
7. Objects Cannot have renaming attribute
8. Functions cannot have renaming parameters
9. Forbidden octal notation
10. Cannot assign values ​​to arguments
11.arguments no longer track parameter changes
12. Forbid using arguments.callee
13. Strict mode only allows global effects A top-level declared function at scope or function scope. That is, it is not allowed to declare a function inside a non-function code block.

14. Certain reserved words cannot be used: implements, interface, let, package, private, protected, public, static, yield.

【Questions and Answers】

this-oriented

var num =222;
var a={
    
    
    num:111,
	say: function () {
    
    
	console.log(this.num)
    }
}
var fn= a.say 
fn()//输出一
a.say()//输出二

var b={
    
    
	num:333,
	say:function (fn) {
    
    
	fn()
    }
}
b.say(a.say)//输出三
b.say = a.say
b.say()//输出四

222
111
222
333

this dynamically points to the running environment of the current function. That is, when calling the same defined function in different scenarios, the point of this is also different.

this always points to the real caller of its function, if not, it points to the global object window

【Programming questions】

1. Print:image-20230413222512959

Each line has no extra spaces at the end, and the last line has no spaces and newlines.

public class Solution {
    
    
    // 请按你的实际需求修改参数
    public static char[] F(int height) {
    
    
        char []a=new char[height*(2*height-1)];
        for (int row=0;row<height;row++){
    
    
            for(int i=0;i<height-row-1;i++){
    
    
                a[row*(2*height-1)+i]=' ';
                a[row*(2*height-1)+2*height-2-i]=' ';
            }
            for(int i=height-row-1;i<height+row;i++){
    
    
                a[row*(2*height-1)+i]='*';
            }
            if(row!=height-1){
    
    
                a[row*(2*height-1)+2*height-2]='\n';
            }
        }
        return a;
    }
}

2. Bracket matching: only "()"

public class Solution {
    
    
    // 请按你的实际需求修改参数
    public static boolean validParentheses(String parens) {
    
    
        // 在这⾥写代码
        int k=0;
        for(int i=0;i<parens.length();i++){
    
    
            if(parens.charAt(i)=='('){
    
    
                k++;
            }
            if(parens.charAt(i)==')'){
    
    

                if(k!=0)
                    k--;
                else
                    return false;
            }
        }
        if(k!=0)
            return false;
        return true;
    }

}

Guess you like

Origin blog.csdn.net/qq_51444138/article/details/130142307