JS Quiz Ten Questions

Source: Internet
Author: User

1. [] + [] + ' foo '. Split ('); [' 1 '] + ' foo '. Split ('); A: ' F,o,o ', ' 1f,o,o ' split converts a string into an array, and the arrays are added by first converting the array to a string and then connecting the strings. 2. New Array (5). toString (); Answer: ",,,," 3. (True + false) > 2 + true; True + False > 2 + true; A: The priority of False,false ' + ' (arithmetic operator) is better than ' > ' (relational operator) 4. function A (x) {return x * 2;}     var a;   alert (a); Answer: function A (x) {    return x * 2; In the process of precompilation and execution, it is equivalent to creating a storage space of a (var A;) and then setting the space content to the function's content 5. var func = function H5course () {alert (typeof h5course);} func (); Alert (typeof H5course); A: function,undefined function h5course is not created in the global function, but in the form of function literals, is assigned to the Func, so in the global scope of the environment, can find the Func , but could not find h5course.  6. var x = 1; if (function f () {}) {x + = typeof F;} alert (x); A: 1undefined When you place a function function in the IF statement, the IF statement can be set, but the function is not defined.     7. Closure function Fun (n,o) { console.log (o);       return {fun:function (m) {return fun (m,n);    }     }; } var a = fun (0); A.fun (1); A.fun (2);    A.fun (3); var B = Fun (0). Fun (1). Fun (2). Fun (3); var c = Fun (0). Fun (1); C.fun (2); C.fun (3); A: undefined 0 0 0undefined 0 1 2undefined 0 1 1 When you perform a fun, you return a function that uses the variable n, and N, which happens to be the formal parameter of the parent function, which forms the closure, n This variable is not released, at the time of the second call, N uses the value obtained after the first call, and so on;  8. var x = 1; var y = 2;  Function Show () {var x = 3;    return {x:x, fun:function (A, b) {x = a + b;  }}} var obj = Show ();  Obj.fun (x, y);  Console.log (obj.x); Console.log (x); A: 3, 1 obj Gets the return value of the show function, which is the object returned by return, and the X of the object after the call to obj is assigned a value of 3. The last sentence of the console output x is the x in the global scope so the value returned should be the global variable x 9.  Closure var a = 0, B = 0;function A (a) {a = function (b) {alert (a + b++); } alert (a++);} A (1); A (2); A: 1,4 The first time a function is called, a function is re-assigned in order to function (b) {alert (a+b++)};alert output A after the value of a and 1, in the initialization of a, parameter A is actually a local variable, when resetting a function, The new a function calls the local variable a in the scope of the original a function, forms a closure, and a local variable is saved.  10. var arr = [];arr[0] = ' a '; arr[1] = ' B '; arr.foo = ' C '; alert (arr.length); Arr.length + = Arr.foo.length;alert (arr.length); A: 2 , 3 array and Array properties Arr.foo, Foo is an attribute of the ARR array, like length  

JS question and answer ten questions

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.