js test questions and answers (6)

1. Which of the following attributes are not the attributes of the event object event
A clientX
B offsetX
C offsetLeft
D target
Correct answer: C
analysis:
offsetLeft is the horizontal coordinate of the element for offsetParent, not the mouse position in the event object

2. The following statement about the incident commissioned by the error is
A event delegate to bind events can solve the problem of too many program
B event delegate use of event capture principle
C event delegates can improve code performance
D event delegate can be applied to click, onmousedown event
correctly Answer: B
analysis:
Event delegation uses the principle of event bubbling

3. 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 correct statement below is
A
B
C
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

4. To prevent the event from bubbling, which of the following methods should be used:
A stopPropagation()
B preventDefault()
C cancelBubble = false
D return false
Correct answer: A
resolution:

5. 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
Resolution:

6. The following can get the property 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

7. The description or definition of the following pairs of constants is incorrect is
A. Constant names can only be capitalized
B const PI = 3.11;
C const pi = 3.14
D Constants cannot be modified after they are defined.
Correct answer: A

8. 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: D is a form event

9. Which of the following event attributes can obtain the horizontal coordinate of the mouse cursor to the visible area of ​​the page (browser border)
A clientX
B offsetX
C pageX
D screenX
Correct answer: A
analysis:
basic attributes

10.JavaScript is where they run scripting language
A server-side (server-side)
B-side Web (browser)
C after the server is running, the results are returned to the customer service side
D after running the client, the server returns the results to
the right Answer: B
analysis:
js is a scripting language that runs in the browser.

11. To check whether the value is NaN, what function should be used
A Number()
B parseInt()
C whoisNaN()
D isNaN()
Correct answer: D
analysis:
a method that should be memorized

12. The following variable declaration error is
A var a;
B let a;
C const a;
D function a;
Correct answer: D
analysis:
A is for ES5 to declare variables, B and C are for ES6 to declare variables/constant methods

D is the wrong option

13. Which of the following is the most recommended wording in the following ES6 string splicing?
A Today’s weather+Very good
B Today’s weather${"Very good"}
C Today's weather+"Very good";D'Today's weather+{" Very good"};D Today's weather+"Very good";D'Today's weather+{very good};
Correct answer: B
Analysis:
Use of template strings

14. Which of the following options is a regular quantifier:
A 100
B num
C +
D.
Correct answer: C
analysis:
+ represents that the character in front of it is repeated 1 to unlimited times

15. The following attributes that can get all child nodes (including text nodes) are:
A firstElementChild
B children
C childNodes
D attributes
Correct answer: C
Analysis:
A. Get the first element node

B. Get all element child nodes

C. Get all child nodes, including text nodes

D. Get all attribute nodes

16.0.1+0.7 == 0.8 (The calculation result of 0.1 + 0.7 is a floating point number)
A true
B false
C Infinity
D NaN
Correct answer: B
Analysis:
Due to the characteristics of the computer storing numbers, there is an error in the calculation of floating point numbers.

0.1+0.7 === 0.7999999999999999

So the result is false

17. The execution result of the following code is function fn(){ console.log( this) }; fn();
A fn
B undefined
C window
D windows
Correct answer: C
analysis:
directly call the function, its internal this points to the global object window

18. The number that cannot be verified in the following regularity 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

19. The execution result of "hello".repeat(3) is
A hello
B hellooo
C helloooo
D hellohellohello
Correct answer: D
analysis:
The function of repeat() is to repeat the string the number of times the parameter is specified

20. How to distinguish the node type of the node object in the html document
A typeof
B type
C nodeType
D nodeName
Correct answer: C
Analysis: The
nodeType property returns the node type of the specified node as a numeric value.

If the node is an element node, the nodeType property will return 1.

If the node is a property node, the nodeType property will return 2.

If it is text content, the nodeType property will return 3.

21. 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)

22. 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 infinite 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;

23. Which of the following is not a method of Math object
A sort()
B floor()
C random()
D abs()
Correct answer: A
analysis:
sort() is an array method

24. Regarding mouseenter, the correct answer is that
A has the same effect as mouseup
B. When the mouse pointer enters the element, a mouseenter event will occur.
C and mouseover are completely the
same. D has the same effect as mouseover.
Correct answer: B
Resolution:
Same effect as mouseover, but Better than mouseover, will not cause bubbling

25. The output result of the following code is var y = 1; var x = y = typeof x; console.log(x);
A undefined
B 1
C y
D error is reported.
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 that when
A let is used internally in a {}, the variable declared by let cannot be accessed from the outside.
B Declaring a variable with let does not promote a variable declared by
C let. This should be done before the variable declaration Variables are not available, 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, the error is that
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 The same event can be bound to multiple functions
D IE8 The following browsers use detachEvent to remove the listener.
Correct answer: A
Resolution: When
the third parameter of addEventListener() is false, it represents the bubbling phase

28. The following related statements about the window.onload event are correct.
A window.onload event may trigger multiple times.
B window.onload event refers to the
C window.onload event can be bound to multiple processing functions after the DOM structure is loaded , and Will trigger the
D window.onload event after all the content of the page is loaded.
Correct answer: D
Analysis: The
load event will be triggered after the document is loaded. At this point, all objects in the document are in the DOM, and all images, scripts, links, and sub-frames have been loaded.

29. The following code segment, the output result after execution is var x=“15”; str=x+5; A=parseFloat(str); document.write(A);
A 20
B 20.O
C NaN
D 155
Correct answer: D
analysis:
string concatenation 15 + 5 results in 155 converted into numbers

30. The execution result of the following code is var fn = "hello";fn();function fn(){ console.log("world")};
A "hello"
B "world"
C undefined
D fn is not function
correct Answer: D
analysis: after
variable declaration promotion & function declaration promotion, the result is

var fn ;

function fn(){ console.log(“world”) };

fn = “hello”

fn()

At this time fn is already a string, the call fails and an error is reported

1. Which of the following options can prevent event bubbling (consider compatibility)
A window.event.cancelBubble=true
B e.preventDefault()
C e.stopPropagation()
D window.event.cancelBubble=false
Correct answer: A, C
analysis :
Compatible with IE and advanced browsers

2. To realize the drag and drop of an element, at least those few events are required, please select
A onmousedown
B onmousemove
C onmouseup
D onmouseover
Correct answer: A, B, C
analysis:

3. The following shows that the timer has
A keyframes
B setInterval
C setTimeOut
D animate
Correct answer: B, C
analysis:
111

4. Which of the following are es6's new
A arrow function
B Deconstruction assignment
C let keyword
D class Definition class
Correct answer: A, B, C, D
analysis:
111

5. The difference between for...of and for...in, the following statement is correct is that
A for in can traverse objects, for of cannot traverse objects
B for of can be used to traverse map collections, for in cannot traverse map collections
C for in traverse arrays What you get is the subscript of the array. For of traverses the array and gets the elements of the array.
D for in traverses the key. For of traverses the value.
Correct answer: A, B, C, D
Analysis:
ABCD

6. The correct statement about event delegation is that
all events of A can achieve event delegation;
B reduces the number of event binding browser redraws and improves the execution efficiency of the program;
C reduces redundant binding of events and saves Event resources.
D can solve the problem that dynamically added element nodes cannot be bound to events;
correct answer: B, C, D
Resolution:
33

7. The correct statement about event binding is
A. Traditional event binding (dom.onclick) cannot bind multiple same events at the same time, and the latter will overwrite the previous ones;
B. Event binding cannot be completed by using event listener
C addEventListener The () method can realize the binding of events.
D Traditional event triggering can only go through the bubbling phase and not the capture phase;
correct answer: A, C
analysis:
1111

8. What are the compatibility issues that will occur in the
event A. Creation of event object
B. Event bubbling
C. Default behavior of browser
D. Acquisition of event source in event delegation
Correct answer: A, B, C, D
analysis:
222111

9. The method to convert a string to uppercase and lowercase is
A str.toSmallCase()
B str.toLowerCase()
C str.toUpperCase()
D str.toUpperChars()
Correct answer: B, C
analysis:

10.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:

11. Which of the following are global methods
A prompt()
B match()
C alert()
D confirm()
Correct answer: A, C, D
analysis:
uuu

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

13. 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 array objects, you cannot traverse strings

14. The correct way to add event listeners to an 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

15. What are the following string methods that support regular expressions?
A indexOf
B match
C replace
D search
Correct answer: B, C, D
parsing:
Some string methods are used together with regular expressions , such as match () matching , Replace () replace, search () find

16. Assuming that the DOM name of an input box is otxt, the following can get the value of the input box is
A otxt.getAttribute("value")
B otxt.value
C otxt["value"]
D otxt.getValue() is
correct Answer: A, B, C
analysis:
getAttribute() is the method to get the attribute value, because value is the attribute value, otxt.value and otxt["value"] can get the attribute value, so ABC is correct, D option, no getValue () method, error

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 pressed (onmousedown) through the coordinates of the mouse and the box OffsetLeft and offsetTop calculate the difference offsetX and offsetY; in the process of dragging the box (onmousemove), the new coordinates and the difference calculated just now are used to calculate the new left and top. This is the principle of dragging. So: left=ev.clientX-offsetX; top=ev.clientY-offsetY; the correct answer is AB

18. Which of the following methods are not regular methods
A search()
B match ()
C replace ()
D test ()
Correct answer: A, B, C
analysis:
ABC are all string methods

19. Determine whether str contains the string "abc", the following is incorrect is
A str.repl(/abc/)!=-1
B str.indexOf('abc') >= 0
C str=='abc'
D 'abc'.includes(str)
correct answer: A, C, D
parsing:
A option: string has no index() method, error;

B option: indexOf() is to check whether the array contains a certain number, it returns the subscript, but does not return -1, the correct option

C option: str=='abc' This is to detect a complete match, it cannot be detected whether it contains, this wording must be completely matched to be correct, so it is wrong

D option: string has no includes() method, this method is an array method, error

20. Which of the following things can be done by destructuring assignment?
A: You can define multiple variables at one time.
B: Can act on the parameters of a function and pass them as objects. The order of the parameters does not need to be the same.
C. The exchange of two numbers can be easily realized.
D Yes. Implement a function to return multiple results
Correct answer: A, B, C, D

Guess you like

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