js basic test questions and answers (3)

1. Multiple-choice questions (30 questions in total, 2 points for each question)
1. What is wrong about the following statement about event delegation?

A Event delegation can solve the problem of too many event binding procedures

B Event delegation uses the principle of event capture

C event delegation can improve code performance

D event delegation can be used in click, onmousedown events

Correct answer: B
analysis:
event delegation uses the principle of event bubbling

2. What attribute is used to get the root node of the HTML file

A documentElement

B rootElement

C documentNode

D documentRoot

Correct answer: A
analysis:
the root node of the html file is html, and the method of obtaining is document.documentElement

3. In the following description of events in Javascript, which is incorrect

A click-mouse click event

B focus——Get focus event

C mouseover-event triggered when the mouse pointer moves to the event source object

D change-event triggered when a field is selected

Correct answer: D
Analysis: The
change event is an event triggered when the input content changes.

Depending on the value of the type attribute of the input, the specific trigger timing is also different

4. Require JavaScript to achieve the following functions: After the content of a text box is changed, clicking on other parts of the page will pop up a message box to display the content of the text box. The following statement is correct


A  <input type="text" onClick="alert(this.value)">

B  <input type="text" onChange="alert(this.value)">

C  <input type="text" onChange="alert(text.value)">

D  <input type="text"onClick="alert(value)">

Correct answer: B
analysis:
onchange event, triggered when the content of the text box changes and the cursor leaves

5. Which of the following are not new in es6:

A Objec.assign

B Array.from

C forEach

D for of loop

Correct answer: C
analysis:
forEach is es5

6. To prevent the default behavior of the browser, which of the following methods should be used

A stopPropagation()

B preventDefault()

C cancelBubble = false

D return true

Correct answer: B
Analysis:
D

7. The execution result of the following code is true

A 1<2 && “5”!=5

B 2>2*1 || “5”==5

C 2>2*1 && 5==5

D 2>=2*1 && “5”===5

Correct answer: B
Analysis:
B

8. Below you can get the attribute of the height of the hidden document part after the browser is scrolled.

A window.body.scrollTop

B document.body.scrollTop;

C document.scrolTop;

D documentElement.body.scrollTop

Correct answer: B
analysis:
basic attributes

9. The description or definition of the following pairs of constants is incorrect.
A constant name can only be capitalized.
B const PI = 3.11;
C const pi = 3.14
D The constant cannot be modified after it is defined.
Correct answer: A
analysis:

10. In the HTML page, the following options do not belong to mouse related events are
A onclick
B onmouseover
C onmousedown
D onchange
Correct answer: D
analysis:

11. In the HTML page, the following options do not belong to keyboard-related events are
A onkeyup
B onkeydown
C oncontextmenu
D onkeypress The
correct answer: C
analysis:

12. Which of the following options is a regular quantifier:

A 100

B num

C +

D .

Correct answer: C
analysis:
+ represents the character in front of it repeats 1~infinitely many times

13. The following are regular methods

A text()

B replace()

C test()

D match()

Correct answer: C
analysis:
This method is used to detect whether the parameter string matches the regular expression

14. Which of the following attributes are not the attributes of the event object event

A offsetX

B clientX

C offsetLeft

D target

Correct answer: C
analysis:
C, get the element's left coordinate for offsetParent in real time

15.The following correct way to get event object is:

A function fn(){ window.event }

B obox.onclick = function( ){ e }

C obox.onclick = function (event){ var evt = event || window.event }

D function fn( e ){ e }

Correct answer: C
analysis:
time objects need to be compatible

16. Which of the following events does not exist

A onclick

B onblur

C onlook

D oninput

Correct answer: C
analysis:
A, click event

B. Focus left event

D, input box input event

17. The following regular rules can not verify the number is

A /[0-9]/

B /\D/

C /0|1|2|3|4|5|6|7|8|9/

D /\d/

Correct answer: B
analysis:
\D matches a non-digit

18. The execution result of the following code is var result = 12 + 2 + "12"-2 * 2; document.write(result);

A 1221222

B 14124

C 1408

D 2820

Correct answer: C
analysis:
var result = 12 + 2 + "12"- 2 * 2;

Look at the right side of the equal sign and calculate from left to right,

12+2 equals 14,

14+"12" is equal to "1412" (string splicing)

"1412"-4 is equal to 1408 (the minus sign will be implicitly converted)

19. If the HTML page contains the code as shown below, write a Javascript function to determine whether the enter key on the keyboard is pressed. The correct code is (the keyboard code of the enter key is 13) <input name="password"; type= "Text" οnkeydοwn="myKeyDown()">

A function myKeyDown(){ if (window.keyCode==13){ alert("You pressed the enter key")}};

B function myKeyDown(){ if (document.keyCode==13){ alert("You pressed the enter key");}}

C function myKeyDown(){ if (event.keyCode==13){ alert("You pressed the enter key")}}

D function myKeyDown(){ if (keyCode==13){ alert("You pressed the enter key")}}

Correct answer: C
analysis:
keyCode is the attribute under the event object, and the keycode equals to 13 means that the enter key is pressed

20. The execution result of the following code is for(var i = 0;i<10;i++){} document.write(i);

A 10

B 11

C 9

D Dead loop

Correct answer: A
analysis:
for(var i = 0;i<10;i++){}

document.write(i);

When the for loop ends, the next statement will be executed. The condition for the end of the loop is when i=10;

21. Which of the following is not a keyword or reserved word in javascript

A class

Have b

C link

D instanceof

Correct answer: C
analysis:
keywords are vocabularies with specific meanings in js, and reserved words are vocabularies that will be used in extensions after js. They cannot be used as variable names and function names. Please check the picture above:

22. Use JavaScript to output to the web page. What <h1>hello</h1>is feasible in the following code is

A  <script type="text/javascript">document.write(<h1>hello</h1>);</script>

B  <script type="text/javascript">document.write("<h1>hello</h1>");</script>

C  <script type="text/javascript"> <h1>hello</h1></script>

D  <h1><script type="text/javascript">document.write("hello");</script></h1>

Correct answer: B
Analysis: The
document.write() method can print the node to the page display, the parameter is a string, if there is a label, it needs to be written completely. document.write ("<h1>hello</h1>"); correct

23. There is var obj = {name: "王大锤", skill: "笑比", logo: "日和漫画"} Use the loop to take out the attribute values ​​in the object one by one and print them correctly.

A for(var i=0; i<obj.length; i++){ console.log(obj[i]); }

B for(var i=0; i<obj.length; i++){ console.log(obj.index); }

C for(var attr in obj){ console.log(obj[attr]) }

D return

Correct answer: C
analysis:
Objects have no length, so for loops cannot be used, and for in needs to be used to traverse. So AB is wrong, C is correct

24. In the following JavaScript statement, which implementation retrieves all the text boxes in the form elements in the current page and clears them all

A for(var i=0;i< form1.elements.length;i++) {

if(form1.elements[i].type==“text”) form1.elements[i].value="";

}

B for(var i=0;i<document.forms.length;i++) {

if(forms[0].elements[i].type==“text”) forms[0].elements[i].value="";

}

C if(document.form.elements.type==“text”) form.elements[i].value=""

D for(var i=0;i<document.forms.length; i++){

for(var j=0;j<document.forms[i].elements.length; j++){

   if(document.forms[i].elements[j].type=="text")     document.forms[i].elements[j].value="";
}

}

Correct answer: D
analysis:
for(var i=0;i<document.forms.length; i++){

for(var j=0;j<document.forms[i].elements.length; j++){

if(document.forms[i].elements[j].type==“text”)

document.forms[i].elements[j].value=""; }

}

Find all text boxes in all forms and set the value to empty.

25. The output of the following code is

var y = 1;

var x = y = typeof x;

console.log(x);

A undefined

B 1

C y

D error

Correct answer: A
analysis:
when typeof x, x is only declared, but not assigned

26. One of the following statements about let declaration variables is incorrect is

When A let is used internally in a {}, the variable declared by the let cannot be accessed from outside

B Use let to declare variables without declaration promotion

The variable declared by C let, the variable is not available before the variable is declared, this phenomenon is called a temporary dead zone;

D let does not allow repeated modification of variables

Correct answer: D
analysis:
constants are not allowed to be modified

27. The following statement about event listeners is wrong

When the third parameter of A addEventListener is false, it means that the event will not be triggered

B Below IE8, use attachEvent to add event listeners

C addEventListener can bind multiple functions to the same event

D Browsers below IE8 use detachEvent to remove the listener.

Correct answer: A
analysis:
when the third parameter of addEventListener() is false, it represents the bubbling phase

28. The following description of the incident is wrong

A The onchange event will be triggered after the text input in the text input box is over

B The onsubmit event will be triggered when the form is submitted

C Clicking on the text input box will trigger the onblur event multiple times

D onmouseover and onmouseenter events are different

Correct answer: C
analysis:
onblur is an event triggered when the focus leaves, and clicking on the text box triggers the onclick event and onfocus event

29. var a = 10; b = 20; c = 4;

++b + c + a++ Which of the following results is correct

A 34

B 35

C 36

D 37

Correct answer: B
analysis:
++ a first operation a++ then operation

30. The output of the following code is

function fn(a) {

 console.log(a);     

 var a = 2;     

 function a() {};     

 console.log(a);

}

fn(2);

A undefined and error

B function a() {}和2

C error and 2

D undefined和function a(){};

Correct answer: B
analysis:
declaration promotion, var is promoted before function.

2. Multiple choice questions (indefinite choice) (20 questions in total, 2 points for each question)
1. The three stages of events in JavaScript are
A, capturing
B, in the target stage
C, bubbling stage
D, proxy stage,
correct answer: A, B, C
analysis:

2. The difference between for...of and for...in, the following statement is correct

A for in can traverse objects, for of cannot traverse objects

B for of can be used to traverse the map collection, for in cannot traverse the map collection

C for in traverses the array to get the subscript of the array, for of traverses the array to get the elements of the array

D for in traversal key for of traversal value

Correct answer: A, B, C, D
Analysis:
ABCD

3. The methods of regular objects include

A test();

B index()

C exec()

D match()

Correct answer: A, C
analysis: There
are only 2 regular object methods, and the other methods are strings.

exec() found the return array, but could not return null.

test() true or false.

4. What compatibility issues will arise in the event

A creation of event object

B 事泡泡

Default behavior of C browser

D. Obtaining event source in event delegation

Correct answer: A, B, C, D
Resolution:
222111

5.var a=“10”, the following can convert a string into a number is
A a*1
B Number(a)
C a-0
D a+0
Correct answer: A, B, C
analysis:

6. Which of the following methods belong to the array:
A sort()
B push()
C indexOf()
D join()
Correct answer: A, B, C, D
analysis:

7. Which of the following is not an array method

A map()

B split()

C filter ()

D test ()

Correct answer: B, D
analysis:
split is a string method test is a regular method

8. Which of the following attributes can be used to change the content of the h1 tag

A innerText

B valueof

C innerHTML

D value

Correct answer: A, C
Analysis:
aaa

9. Statements that can be used to traverse strings are

A for-in

B for

C for-of

D forEach

Correct answer: A, B, C
Analysis:
Array.prototype.forEach is a method of an array object, it cannot traverse the string

10. The following are new content of ES6

A strict mode

B arrow function

C destructuring assignment

D class

Correct answer: B, C, D
analysis:
strict mode already exists in ES5.

But in many syntaxes of ES6, strict mode is used by default

11. The method or property in the event object that can prevent the event from bubbling is

A e.stopPropagation()

B e.preventDefault()

C e.cancelBubble = true

D event.returnValue = false

Correct answer: A, C
Analysis:
B, D are to prevent the default behavior of the browser

12. The correct way to add event monitoring to the element is

A oDiv.onclick ()

B oDiv.attachEvent ()

C oDiv.addEventListener ()

D oDiv.detachEvent ()

Correct answer: B, C
Analysis:
The correct usage of A is oDiv.onclick = function () ()

D is the method of IE8 contact event binding

13. Which of the following string methods support regular expressions

A indexOf

B match

C replace

D search

Correct answer: B, C, D
parsing:
Some methods of string are used together with regulars, such as match () matching, replace () replacement, search () search

14. How to stop events from bubbling up

A cancelBubble

B return true

C event.preventDefault

D event.stopPropagation()

Correct answer: A, D
analysis: The
browser has some default behaviors, such as right-click menu, click to jump, text selection effect, drag and drop ghosting, etc. If there are inexplicable problems, it may also be caused by the default behavior and prevent the default behavior. : Event.preventDefault and return false, to prevent bubbling: cancelBubble and event.stopPropagation();.

15. The following shows the mouse events

A onclick

B onmouseover

C onmouseout

D onmousemove

Correct answer: A, B, C, D
Analysis:
onchange is triggered when the content changes, triggering the call to the function writeIt (), the function of this function is to copy the content of the second text box to the first text box.

16.The following are meaningful abbreviations in regular rules:

A \d

B \w

C \s

D \S

Correct answer: A, B, C, D
analysis:

Regular expression

17. In the drag effect, the events that need to be used are

A onmousemove

B onmousedown

C onmouseup

D onclick

Correct answer: A, B, C
analysis:
the principle of dragging: when pressing (onmousedown) the difference between the coordinates of the mouse and the offsetLeft and offsetTop of the box is used to calculate the difference offsetX and offsetY; while pressing the box (onmousemove) Calculate the new left and top with the new coordinates and the difference just calculated. This is the principle of drag and drop. So: left=ev.clientX-offsetX; top=ev.clientY-offsetY; the correct answer is AB

18. The new keywords for declaring variables in ES6 are

A function

B let

C const

D p

Correct answer: B, C
analysis:
let is used to declare variables

const is used to declare constants

19. Which of the following can be done by destructuring assignment

A Multiple variables can be defined at one time

B can be used on the parameter passing of the function, passed as an object, and the order of the parameters does not need to be consistent

C can easily realize the exchange of two numbers

D can implement a function to return multiple results

Correct answer: A, B, C, D
Resolution:
122

20. The following descriptions of the attributes in the event object are correct

A event.clientX, event.clientY: get the x-axis value and y-axis value of the mouse relative to the browser visual window

B event.pageX and event.pageY are similar to event.clientX and event.clientY, but they use document coordinates (relative to the x-axis distance and y-axis distance of the document) instead of window coordinates

C event.offsetX, event.offsetY: the X and Y coordinates of the mouse relative to the upper left corner of the user's monitor screen

D event.screenX, event.screenY: X, Y coordinates of the mouse relative to the event source element (srcElement)

Correct answer: A, B
analysis:
the knowledge of the three major families should be familiar

Guess you like

Origin blog.csdn.net/weixin_49299412/article/details/107867447