JavaScript basic test questions (3) and answers

javascript basic test questions (3)

Multiple choice

  1. The following statements about event delegation are wrong (B)
    A. Event delegation can solve the problem of too many event binding programs.
    B. Event delegation uses the principle of event capture.
    C. Event delegation can improve code performance.
    D. Event delegation can be used in click and onmousedown events.
    //Event delegation uses the principle of event bubbling

  2. Regarding the 6-digit zip code declared by the regular expression, the following code is correct (C)
    A var reg = /\d6/;
    B var reg = \d{6};
    C var reg = /\d{6}/;
    D var reg = new RegExp("\d{6}");
    //D option is wrong, the correct way to write it should be var reg = new RegExp("\d{6}")

  3. JavaScript is required to implement 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 (B)
    A
    B
    C
    D <input type="text"onClick="alert(value)">
    //onchange event, triggered when the content of the text box changes and the cursor leaves

  4. To prevent the default behavior of the browser, which of the following methods should be used (B)
    A stopPropagation()
    B preventDefault()
    C cancelBubble = false
    D return true

  5. The following objects or arrays are created in the wrong way (B)
    A var obj = {};
    B var obj = {[]}
    C var obj = [{}]
    D var obj = {age:30}

  6. Below you can get the attribute of the height of the hidden document part after the browser is scrolled (B)
    A window.body.scrollTop
    B document.body.scrollTop;
    C document.scrolTop;
    D documentElement.body.scrollTop

  7. Which of the following event attributes can get the horizontal coordinate of the mouse cursor to the page viewable area (browser border) (A)
    A clientX
    B offsetX
    C pageX
    D screenX

  8. Analyzing the following JavaScript code segment, the output result is var a=15.59; document.write(Math.round(a)) (B)
    A 15
    B 16
    C 15.5
    D 15.4

  9. The following variable declaration error is (D)
    A var a;
    B let a;
    C const a;
    D function a;
    //A is the ES5 declaration variable, B and C are the ES6 declaration variable/constant method, D is the wrong option

  10. The following regular methods are (C)
    A text()
    B replace()
    C test()
    D match()
    //This method is used to detect whether the parameter string matches the regular expression

  11. What is the keyCode value of the Enter key? (B)
    A 12
    B 13
    C 32
    D 33

  12. Which of the following attributes are not the attributes of the event object event (C)
    A offsetX
    B clientX
    C offsetLeft
    D target
    //C, real-time acquisition of the element's left coordinate for offsetParent

  13. How to distinguish the node type of the node object in the html document (C)
    A typeof
    B type
    C nodeType
    D nodeName
    //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.

  14. The execution result of the following code is var arr = [1,11,2,22,3,4]; arr.sort(); document.write(arr); (A)
    A 1,11,2,22,3, 4
    B 1,2,3,4,11,22
    C 22,11,4,3,2,1
    D Error report
    //arr.sort(); used directly, you cannot sort numbers above 10, so you will get : 1,11,2,22,3,4

  15. 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()”> (C)
    A function myKeyDown(){ if (window.keyCode13){ alert("You pressed the enter key")}};
    B function myKeyDown(){ if (document.keyCode
    13){ alert("You pressed the enter key");}}
    C function myKeyDown(){ if (event.keyCode13){ alert("You pressed the enter key")}}
    D function myKeyDown(){ if (keyCode
    13){ alert("You pressed the enter key")}}
    //eyCode is an attribute under the event object, and the keycode equals to 13 means that the enter key is pressed

  16. In Javascript, the event that is triggered when the element loses focus is (D)
    A fouce
    B unload
    C mouseover
    D onblur
    //onblur is triggered when the focus is lost, and the focus is onfocus

  17. The execution result of the following code is for(var i = 0;i<10;i++){} document.write(i); (A)
    A 10
    B 11
    C 9
    D infinite loop
    //for(var i = 0;i <10;i++){}
    document.write(i);
    At the end of the for loop, the next statement will be executed. The condition for the end of the loop is when i=10;

  18. Which of the following is not a data type in javascript (D)
    A string
    B boolean
    C undefined
    D num
    //Data types are divided into two categories:
    basic data types: string, number, undefined, boolean, null
    composite data type (reference): array , Function, json...

  19. Which of the following is not a method of Math object (A)
    A sort()
    B floor()
    C random()
    D abs()
    //sort() is an array method

  20. Use JavaScript to output to the web page

<h1>hello</h1>

What is feasible in the following code is (B)

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>
  1. There is var obj = {name: "王大锤", skill: "笑比", logo: "日和漫画"} Use a loop to take out and print the attribute values ​​in the object in turn. The correct one is (C)
    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
    //Object has no length, so you can't use for loops, you need to traverse with for in. So AB is wrong, C is correct

  2. The execution result of the following code will definitely not be (D)
    document.write(parseInt(Math.random()*3))
    A 1
    B 0
    C 2
    D 3
    //Math.random() gets 0-1 1 can not get Multiply by 3 is 0-3 and 3 cannot be obtained

  3. The execution result of the following code is (A)
    var i = 12;
    var sum = i++ + ++i + ++i*2 + i-- + i--;
    document.write(sum + "" + i);
    A 85 13
    B 84 12
    C 83 11
    D 85 14

  4. If today is May 14, 2006, after analyzing the following JavaScript code to run, it will be displayed on the webpage (D)
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth();
    var date = now.getDate();
    document.write(year+" "+month+" "+date);
    A 2006 05 14
    B 2006 5 14
    C 2006 04 14
    D 2006 4 14
    //The month starts from 0

  5. The output of the following code is (A)
    var y = 1;
    var x = y = typeof x;
    console.log(x);
    A undefined
    B 1
    C y
    D When an error is reported
    //typeof x, x is only declared but not Assigned

  6. The syntax format of the string match method is: str.match(searchvalue) or str.match(regexp). The following statement is wrong () Note: RegExp is a regular constructor (C)
    A If the regexp parameter is not a RegExp object, You need to pass it to the RegExp constructor first, and convert it to
    an array where the return value of the RegExp object B function stores the matching result. The content of the array depends on whether the regexp has a global flag g
    C The content of the array returned by the global match is the same as the content of the array returned by the non-global match
    D code '1abc2qwe3'.match(/\d+/g); will find the characters When all numbers in the string are
    matched globally, all content that matches the regexp is returned. When non-globally matched, the first element is the matched content, and the following is the content captured by the group

  7. The following statement about event listeners is wrong (A)
    A. When the third parameter of 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 Browsers below IE8 use detachEvent to remove the listener.
    //When the third parameter of addEventListener() is false, it represents the bubbling phase

  8. The following code snippet, the output after execution is var x=“15”; str=x+5; A=parseFloat(str); document.write(A); (D)
    A 20
    B 20.O
    C NaN
    D 155
    //String splicing 15 + 5 results in 155 converted into numbers

  9. The output of the following code is (B)
    function fn(a) { console.log(a); var a = 2; function a() {}; console.log(a); } fn(2); A undefined and Error B function a() {} and 2 C Error and 2 D undefined and function a(){}; //Declaration promotion, var is promoted before function.










  10. Regular expression: / 1 What does \w{4,9}$/ mean? (A)
    A starts with a letter, and the content can only contain alphanumeric underscores, and the total length is between 5 and 10.
    B starts with a letter, and the content must contain alphanumeric underscores , The total length is between 4 and 9
    C does not start with a number, the content is arbitrary, the total length is 5 to 10
    D does not start with a number, the content is arbitrary, the total length is 4 to 9
    // /[a-zA-Z]/ Character class represents any letter
    // \w represents any alphanumeric underscore
    // The character before the {n,m} code is repeated at least n times, and at most m times

Multiple choice

  1. To realize the drag and drop of an element, at least those events are required, please select (A, B, C)
    A onmousedown
    B onmousemove
    C onmouseup
    D onmouseover

  2. Which of the following are new in es6 (A, B, C, D)
    A arrow function
    B destructuring assignment
    C let keyword
    D class definition class

  3. The methods of regular objects include (A,C)
    A test();
    B index()
    C exec()
    D match()
    //There are only 2 regular object methods, and the other methods are strings. exec() found the return Array, can't find return null.test() true or false.

  4. The following statement about strict mode is correct (A,B,C,D)
    A Use "use strict" to define strict mode
    B Strict mode can be defined at the top of the function or the top of the program
    C In strict mode, the variable a When there is no declaration, a = 10; such an assignment will report an error
    D. Strict mode execution is more efficient

  5. The correct statement about event delegation is (B, C, D)
    A All events can implement event delegation;
    B reduces the number of event-bound browser redraws and improves the execution efficiency of the program;
    C reduces event redundancy More binding saves event resources.
    D can solve the problem that dynamically added element nodes cannot bind events;

  6. The correct statement about event binding is (A, C)
    A system event binding (dom.onclick), you cannot bind multiple same events at the same time, and the latter will overwrite the previous one;
    B cannot complete the event binding by using event monitoring given
    C addEventListener () method can realize the event of tie
    D traditional event triggered only after the bubbling phase, not after the capture phase;

  7. What compatibility issues will occur in the event (A, B, C, D)
    A creation of event object
    B bubbling of event
    C default behavior of browser
    D acquisition of event source in event delegation

  8. The method to convert a string to uppercase and lowercase is (B, C)
    A str.toSmallCase()
    B str.toLowerCase()
    C str.toUpperCase()
    D str.toUpperChars()

  9. The following expression can generate random numbers between 1-10 (including 1, 10) is (B,C)
    A Math.floor(Math.random()*9)
    B Math.ceil(Math.random()*10)
    C Math.floor(Math.random()*10)+1
    D Math.floor(Math.random()*10)

  10. var a=“10”, the following can realize the conversion of a string into a number is (A, B, C)
    A a*1
    B Number(a)
    C a-0
    D a+0

  11. Which of the following methods belong to the array (A,B,C,D)
    A sort()
    B push()
    C indexOf()
    D join()

  12. Which of the following is not an array method (B, D)
    A map()
    B split()
    C filter()
    D test ()
    //split is a string method test is a regular method

  13. Which of the following attributes can be used to change the content of the h1 tag (A, C)
    A innerText
    B value of
    C innerHTML
    D value

  14. The correct way to add event listener to the element is (B, C)
    A oDiv.onclick()
    B oDiv.attachEvent()
    C oDiv.addEventListener()
    D oDiv.detachEvent()
    //The correct usage of A is oDiv.onclick = function () {}
    //D is the method of IE8 contact event binding

  15. Which of the following string methods support regular expressions (BC, D)
    A indexOf
    B match
    C replace
    D search
    //Some methods of string are used with regular expressions , such as match () matching, replace () replacement , Search() to find

  16. How to prevent event bubbling (A, D)
    A cancelBubble
    B return true
    C event.preventDefault
    D event.stopPropagation()
    //Browser has some default behaviors, such as right-click menu, click to jump, text selection effect, drag ghost Wait, if there is an inexplicable problem, it may also be caused by the default behavior. Prevent the default behavior: event.preventDefault and return false, prevent bubbling: cancelBubble and event.stopPropagation();.

  17. The following represents mouse events (A,B,C,D)
    A onclick
    B onmouseover
    C onmouseout
    D onmousemove

  18. The following are the meaningful abbreviations in regularization: (ABCD)
    A \d
    B \w
    C \s
    D \S

  19. Which of the following methods are not regular methods (A, B, C)
    A search()
    B match ()
    C replace ()
    D test ()
    //ABC is a string method

  20. Which of the following things can be done by destructuring assignment (A, B, C, D)
    A can define multiple variables at one time
    B can be used on the parameters of a function, passed as objects, and the order of parameters does not need to be consistent.
    C can be easily implemented The exchange of two numbers
    D can realize a function to return multiple results


  1. a-zA-Z ↩︎

Guess you like

Origin blog.csdn.net/Bob_Yan623/article/details/108692380