30 javascript questions that you "cannot do all" and javascript questions

Source: Internet
Author: User

30 javascript questions that you "cannot do all" and javascript questions
1. The running result of the following expression is: ["1", "2", "3"]. map (parseInt). ["1", "2", "3"] B. [1, 2, 3] C. [0, 1, 2] D. others =================== answer: D, parseInt the second parameter range is: 2-32. If 0 is input, the default value is 10. View the parseInt function definition by yourself
2. The running result of the following expression is: [typeof null, null instanceof Object]. ["object", false] B. [null, false] C. ["object", true] D. others
====================== Answer: A, on the instanceof in-depth explanation, please refer to: http://www.ibm.com/developerworks/cn/web/1306_jiangjj_jsinstanceof/
3. The running result of the following expression is: [3, 2, 1]. reduce (Math. pow), []. reduce (Math. pow)]. error B. [9, 0] C. [9, NaN] D. [9, undefined]
=, The first element of the array is used as the initValue, but the empty array does not have the first element 4. The running result of the following expression is: var val = "value "; console.info ("Value id" + (val = "value ")? "Something": "Nothing"); A. SomethingB. NothingC. NaND. Others
============ Answer: A. Comparison of JavaScript is divided into two types: Value Type comparison and reference type comparison. The value type only compares values equal to 5. The following expression runs the result: var name = "World"; (function () {if (typeof name = "undefined ") {var name = "Jack"; console.info ("Goodbye" + name);} else {console.info ("Hello" + name) ;}}) ();. goodbye JackB. hello JackC. goodbye undefinedD. hello undefined
============== Answer: A. JS variables act only on the global and function level, and then the variables declared by var have A hoisting process 6, the running result of the following expression is: var START = END-100; var count = 0; for (var I = START; I <= END; I ++) {count ++;} lele.info (count); A.0B. 100C. 101D. others ====================== answer: D, an error will be reported, and the END is not defined
7. The running result of the following expression is: var arr = [0, 1, 2]; arr [10] = 10; arr. filter (function (x) {return x === undefined});. [undefined x 7] B. [0, 1, 2, 10] C. [] D. [undefined]
============== Answer: C. The filter does not process the undefined Element 8 in the array. The result of the following expression is: var two = 0.2; var one = 0.1; var eight = 0.8; var six = 0.6; [two-one = one, eight-six = two];. [true, true] B. [false, false] C. [true, false] D. others
=========== Answer: C. I don't know why. What is the difference between 0.1 and 0.2 floating point numbers? Result 9: function showCase (value) {switch (value) {case "A": console.info ("Case A"); break; case "B": console.info ("Case B"); break; case undefined: console.info ("undefined"); break; default: console.info ("Do not know! ") ;}} ShowCase (new String (" A "); A. Case AB. Case BC. Do not knowD. undefined
============== Answer: C, switch use ===to compare 10. The running result of the following expression is: function showCase (value) {switch (value) {case "A": console.info ("Case A"); break; case "B": console.info ("Case B"); break; case undefined: console.info ("undefined"); break; default: console.info ("Do not know! ") ;}} ShowCase (String (" A "); A. Case AB. Case BC. Do not knowD. undefined
================== Repeated with the previous question 11. The running result of the following expression is: function isOdd (num) {return num % 2 = 1;} function isEven (num) {return num % 2 = 0;} function isSane (num) {return isEven (num) | isOdd (num);} var values = [7, 4, "13",-9, Infinity]; values. map (isSane);. [true, true] B. [true, true, false] C. [true, false, false] D. [true, true, false, false]
========================== Answer: C. The remainder of a negative number is 12. The running result of the following expressions is: [parseInt (3, 8), parseInt (3, 2), parseInt (3, 0)]. [3, 3] B. [3, 3, NaN] C. [3, NaN, NaN] D. others
============== Answer: D, [3, NaN, 3]. For more information, see question 13. The following expression runs as an Array. isArray (Array. prototype). trueB. falseC. error D. others
=========================== Answer:
14. The running result of the following expression is: var a = [0]; if ([0]) {console.info (a = true );} else {console.info ("else");}. trueB. falseC. "else" D. others ================== answer: B. The array is of the reference type. Use ===to compare whether it is the same object.
15. The running result of the following expression is: [] = [] A. trueB. falseC. Error D. Other
============= Answer: B. refer to the previous question
16. The running result of the following expression is: [("5" + 3), ("5"-3)]. ["53", 2] B. [8, 2] C. error D. others
================= Answer: A, no need to explain
17. The running result of the following expression is: 1 +-++-+ 1A. trueB. falseC. error D. others ================== answer: C, abnormal Question 18. The following expression runs: var arr = Array (3 ); arr [0] = 2arr. map (function (elem) {return "1" ;});. [2, 1, 1] B. ["1", "1", "1"] C. [2, "1", "1"] D. others
================== Answer: D. map does not process undefined elements. The result should be: ["1", undefined, undefined] 19. The running result of the following expression is: function sidEffecting (arr) {arr [0] = arr [2];} function bar (a, B, c) {c = 10; sidEffecting (arguments); return a + B + c;} bar (1, 1); A.3B. 12C. error D. others
=============== Answer: 21.
20. Run the following expression: var a = 111111111111111110000; B = 1111; console.info (a + B); a.1111111111111111111b. 1111111111111111116c. NaND. Infinity.
=========================== Answer: B. I don't know the specific reason. I guess the integer is out of bounds? 21. The running result of the following expression is: ar x = []. reverse; x (); A. [] B. undefinedC. Error D. window
======================= Answer: C. You can use your browser to find out the cause 22. The result of the following expression is: Number. MIN_VALUE> 0A. trueB. falseC. error D. others
====================== Answer: A23, the following expression is run: [1 <2 <3 <2 <1]. [true, true] B. [true, false] C. error D. others
================== Answer: A. Check the comparison character combination and the comparison of true and integer types. The following expressions run as follows: 2 = [[2]. trueB. falseC. undefinedD. others
=========================== Answer: A, [[[2]. toString () is "2", which is equivalent to constantly calling the join method of the array. 2 = "2" is not required. 25. The running result of the following expression is: [3. toString (), 3 .. toString (), 3... toString ()]. ["3", error, error] B. ["3", "3.0", error] C. [error, "3", error] D. others
==================== Answer: C. Two vertices are required to call a method of the Number type, because if you write a vertex, it will be parsed to a floating point number 26. The following expression runs: (function () {var x1 = y1 = 1 ;}) (); console.info (y1 ); console.info (x1); A.1, 1B. error, errorC.1, errorD. others
============================== Answer: C, y1 is equivalent to 27 defined on window, list the compatibility issues with IE and FF scripts 28. What are the problems with the following functions? How can we improve it? Function initButtons () {var body = document. body, button, I; for (I = 0; I <5; I ++) {button = document. createElement ("button"); button. innerHTML = "Button" + I; button. addEventListener ("click", function (e) {alert (I); 2015, false); body. appendChild (button) ;}} initButtons ();
====================== Closure problem, note that the closure holds some variables, not the value of the variable, so during execution, alert is 429, write a piece of code to identify the most frequently occurring characters in a string and count the number of occurrences. Var str = "aswerwsdfsfs", result = {'ch': '', 'num':-1}, str. split (""). forEach (function (c, k ){!! Result [c]? Result [c] ++: (result [c] = 1); (result [c]> result [num]) & (result [ch] = c );})
Console. log (result)
===================================30, what are the differences between the two codes? SetTimeout (function () {/* code block */setTimeout (arguments. callee, 10) ;}, 10); setInterval (function () {/* code block */}, 10); the question is taken from the ultra-practical javascript code segment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.