js basic test questions and answers (2)

1. Multiple choice questions
1. Given the array var arr = [1,2,3,4,5], after executing arr.pop(), the length of the array is

A 4

B 5

C 6

D 7

Correct answer: A
analysis:
arr.pop() is the data after deleting the array

2.var array = new Array(5); array.push(8); The length of the array is

A 5

B 6

C 7

D 8

Correct answer: B
Analysis:
new Array(5); Create an empty array with a length of 5, the push method adds one bit after the array, and the result is 6

After 3.3 seconds, the picture disappears, which of the following methods should be used

A hide()

B setTimeout()

C ClearInterval

D clearTimeout()

Correct answer: B
analysis:
setTimeout delayer

4. Which of the following methods can find the element whose class name is "xm"

A document.getElementsByClassName(“xm”)

B document.getElementsByName(“xm”)

C document.Class(“xm”)

D document.ByName(“xm”)

Correct answer: A
parsing:
document.getElementsByClassName("xm"); Get elements whose class is xm

5. If a box pops up where you can enter information, which method can be used

A confirm()

B prompt()

C alert()

D and
above are all right

Correct answer: B
analysis:
prompt

6. How to quickly clear the array arr

A arr.length = 0

B arr = “”

C arr.length = “”

D arr.length = []

Correct answer: A
analysis:
forcibly set the length of the array to 0, you can clear the array

The result of 7.Math.floor(-3.14) is ()
A -3.14
B -3
C -4
D 3.14
Correct answer: C
analysis:

8. Which of the following is the event triggered by the window size change

A onmouseover

B onresize

C onmouseout

D onclick

Correct answer: B
Resolution:
1

9. Determine the output of the following code as var a = 1; var b = a * 0; var a; if (b == b) {console.log(b * 2 + “2”- 0 + 4);} else {console.log(!b * 2 + "2"- 0 + 4);}
A 6
B NaN
C 22
D 26
Correct answer: A
analysis:

10. Please read the following code var num = Math.floor(Math.random()*100); The value range of num in the above code is

A 0–100

B 1–99

C 0–99

D 1–100

Correct answer: C
analysis:
formula: Math.random()*(max-min+1)+min

11. What is wrong about the nodeName description

The node name of the A element node is always the label name

The node name of the B text node is always #document

The node name of the C text node is always #text

The node name of the D attribute node is always the attribute name

Correct answer: B
analysis: the
text node name is #text

  1. Please read the column code <ul id="list">文本<li>list1</li> <li>list2</li> <li>list3</li> </li> <script> var list = document.getElementById("list"); console.log(list.childNodes[0].nextSibling); </script>above code is output

A <li>list1</li>

B " "

C <li>list2</li>

D <li>list3</li>

Correct answer: A
analysis:
list.childNodes[0] is a text node

13. Which of the following objects does not belong to the bom object
A document
B location
C history
D offsetWidth
Correct answer: D
analysis:

14. Regarding the statement of the Math object in JavaScript, the correct
answer is that the result returned by A Math.ceil(512.51) is 512
B Math.floor() method is used to round down the number
C Math.round(-512.51) returns The result of is -512
D Math.random() returns a result range of 0-1, including 0 and 1.
Correct answer: B
analysis:

15.var arr = [3,4,6], delete the last item in the array
A arr.pop()
B arr.pop(6)
C arr.shift()
D arr.shift(6)
Correct answer: A
Analysis:

16.var arr = [5,3,2,4]; var res = arr.splice(0); console.log(res) The result is
A [5,3,2,4]
B [5]
C [5 ,3]
D [2,4]
Correct answer: A
Analysis:

17.
A reverse()
B sort()
C join()
D find() to realize the reverse order method of arrays.
Correct answer: A
analysis:

18.var str = "qianfengana"; var res = str.lastIndexOf("a"); console.log(res); The output result is
A 9
B 2
C 7
D 10
Correct answer: D
Analysis:

19. The method of adding nodes
A parent node. appendChild()
B parent node. append()
C parent node. prepend()
D parent node. prependChild()
Correct answer: A
resolution:

20.var arr = [how,are,you]; arr.reverse(); alert(arr)

A how,are,you

B you,are,how

C h,o,w,a,r,e,y,o,u

D u,o,y,e,r,a,w,o,h

Correct answer: B
analysis:
reverse reverse, directly modify the original array

21. Which of the following descriptions of innerHTML and innerText are correct?

A innerHTML will be parsed into html tag rendering, innerText is a plain text display

B innerHTML will be escaped, such as <will be converted to <, innerText will be rendered as it is

C innerHTML and innerText will be parsed into html tags for rendering

D innerHTML and innerText are both plain text display

Correct answer: A
parsing:
innerhtml will not be escaped

22. What is the correct statement about setInterval(check, 10)?

A The program is executed 10 times in a loop

The B check function is executed every 10 seconds

C 10 is passed as a parameter to the function check

D check function is executed every 10 milliseconds

Correct answer: D
analysis:
basic timer concepts

23. Get the millisecond value from midnight on 01/01/1970 to the current time

A getTime()

B getDay()

C setDate()

D getDate()

Correct answer: A
Resolution:
A

24.var arr = [100,4,2,3,200]; alert(arr.sort(function(a,b){return b - a;}))

A 2,3,4,100,200

B 200,100,4,3,2

C 100,2,200,3,4

D 4,3,200,2,100

Correct answer: B
analysis:
sort adds a comparator function, and ba is sorted in descending order

25. In JavaScript, the following statement about the window object method is wrong

A window object includes location object, history object and document object

The function bound to the B window.onload event will be executed after the page is loaded

The C window.open() method is used to close the specified URL path

D window.close() method is used to close the browser window

Correct answer: C
analysis: The
open() method is used to open a new browser window or find a named window.

26.0.1+0.7==0.8 This expression returns

A true

B false

C Infinity

D NaN

Correct answer: B
Analysis:
B

27. Which attribute can get the vertical distance that the scroll bar has been scrolled

A document.scrollTop

B document.top

C document.body.scrollTop

D window.scrollTop

Correct answer: C
Analysis:
C

28. The output of the following code is var bool = true; setTimeout(function(){ bool = false },0); console.log(bool)

A false

B true

C error

D undefined

Correct answer: B
Analysis:
This question is tested asynchronously and belongs to the knowledge with high difficulty level mentioned earlier. Asynchronous program is executed later than synchronous program

29.var arr = [1,2,3,4]; arr.concat(1,2,4,[1,2,3],5); alert(arr.length)

A 4

B 9

C 11

D 5

Correct answer: A
analysis:
concat does not modify the original array

30.var arr = [1,2,3,4]; arr.join("&"); console.log(arr);

A [1,2,3,4]

B 1&2&3&4

C [1&2&3&4]

D 1,2,3,4

Correct answer: A
analysis:
join does not change the original array.

2. Multiple choice questions (indefinite choice)

1. Which of the following methods can round a decimal

A Math.floor()

B Math.ceil ()

C Math.round()

D Math.abs()

Correct answer: A, B, C
Analysis:
Math.floor() rounds down; Math.ceil() rounds up; Math.round() rounds up

2. Which of the following objects can be created by means of constructor

A Date

B Math

C Array

D String

Correct answer: A, C, D
Analysis:
Math is a mathematical object, you can use it directly without creating

3. What are the built-in objects of the window object

A location

B event

C history

D document

Correct answer: A, C, D
Analysis:
event is not a built-in object

4. Which of the following ways to find the page element is an array-like (pseudo-array)

A querySelectorAll()

B getElementsByName()

C getElementsByTagName()

D getElementsByClassName()

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

5. There are ways to add elements to the array

A push

B pop

C slice

D unshift

Correct answer: A, D
Resolution:
AD

6. The following are window sub-objects

A history

B location

C navigator

D document

Correct answer: A, B, C, D
Analysis:
window is a global object, there are many sub-objects below, and the sub-objects have corresponding properties and methods. History, location, navigator, and document are all commonly used sub-objects. You can print to the console to view the properties and methods of the window object.

console.log(window);

7. In JavaScript, which of the following statements can hide the div whose id is flower

A document.getElementById(“flower”).style.display=“none”;

B document.getElementById(“flower”).style.display=“hidden”;

C document.getElementById(“flower”).style.visibility=“none”;

D document.getElementById(“flower”).style.visibility=“hidden”

Correct answer: A, D
analysis: the
display attribute has no hidden value;

The visibility attribute does not have a value of none

8. Which of the following ways can traverse the array

A for

B for-in

C for-by

D switch

Correct answer: A, B
analysis:
for is a common loop statement, for-in is mainly used to traverse non-array objects, but it can also traverse arrays

There is no for-by in js, switch is a branch structure

9. Which of the following are string methods

A replace()

B split()

C join()

D indexOf()

Correct answer: A, B, D
analysis:
replace is to replace, split is to divide characters into an array according to the specified string, indexOf is to return the index according to the specified character, and join is to convert the array into a string

10. Which of the following are array methods

A charAt()

B sort()

C push()

D filter ()

Correct answer: B, C, D
analysis:
sort is the sorting of the array, push is added at the last bit of the array, filter can filter the data while traversing the array, charAt can return characters according to the specified index, not an array method

11. Which of the following methods to convert an array to a string

A join()

B toString()

C split ()

D concat()

Correct answer: A, B
analysis:
solit is to split characters into arrays, concat is to merge arrays

12. What is incorrect about the array in javascript is

The length of the A array must be given when it is created, and cannot be changed afterwards

B Since the array is an object, the new operator must be used to create the array

The types of elements in the C array can be different

The D array can be initialized at the same time as it is declared

Correct answer: A, B
analysis:
the length of the array can be changed by forcibly setting the value of the specified index; the array can also be created literally

13. Mouse events are:

A onmouseover

B onclick

C onmouseout

D onmousemove

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

14. There are methods for setting the year, month and day for the date object

A setFullYear

B setYear

C setDay

D setDate

Correct answer: A, D
Resolution:
AD

15. There are ways to turn on the timer and delayer

A clearInterval()

B setTimeOut()

C setTimeout()

D setInterval()

Correct answer: C, D
Analysis:
CD

16. The following methods can intercept string fragments

A substr()

B substring()

C split ()

D slice()

Correct answer: A, B, D
analysis:
split is to split the string, the others can be intercepted

17. What are the built-in objects of the window object

A document

B history

C href

D location

Correct answer: A, B, D
analysis:
document is the document object of the window, history is the history object of the window, and location is the url object of the window

18. The following description of the string is correct

A The length of the string can be obtained through the length attribute

B string can get the index corresponding to a character through charAt()

C string can get the index corresponding to a character through indexOf()

D string can be converted into an array by join()

Correct answer: A, C
Analysis:
AC

19. The following are not keywords or reserved words

A class

B let

C style

D script

Correct answer: C, D
analysis:
Keyword refers to the name that is used for other purposes in the grammar, and reserved words refer to the future expansion of Javascript, which cannot be used as variable names, function names and tag names; refer to the following table to see, class And let are key reserved words, style and script are not.

20. Which of the following are methods belonging to the Date object

A setMonth()

B getFullYear()

C setDate()

D random()

Correct answer: A, B, C
Analysis:
random is the method of Math

Guess you like

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