Javascript abnormal questions

Source: Internet
Author: User

Some abnormal JavaScript questions I just found are just half done. I would like to share them with friends in the garden. These questions are for the third edition of ecmascript. All the original questions are multiple-choice questions and there are alternative answers. Here I have removed all the answers, because if some questions do not look at the answers, you will know why, after reading the answer, you hesitate. So, just do it and give yourself some confidence and trust yourself!

 
//Question 1(Function(){Return TypeofArguments ;})();
 //  Question 2  VaR F = Function G (){ Return 23 ;};  Typeof G ();  //  Question 3 ( Function  (X ){  Delete  X;  Return  X ;})( 1 );  //  Question 4  VaR Y = 1, x = y = Typeof  X;  // Question 5 ( Function  F (f ){  Return   Typeof  F ();})(  Function (){ Return 1 ;});  //  Question 6  VaR Foo = {Bar:  Function (){ Return  This  . Baz;}, Baz: 1 };(  Function  (){  Return   Typeof Arguments [0 ] () ;}) (FOO. bar );  //  Question 7  VaR Foo = {Bar:  Function (){ Return   This . Baz;}, Baz: 1 }  Typeof (F = Foo. bar )();  //  Question 8  VaR F = ( Function F (){ Return "1 ";}, Function G (){ Return 2 ;})();  Typeof  F;  // Question 9  VaR X = 1 ;  If ( Function  F () {}) {x + = Typeof  F;} X;  //  Question 10  VaR X = [ Typeof X, Typeof Y] [1 ];  Typeof  Typeof  X;  //  Question 11 ( Function  (FOO ){  Return   Typeof  Foo. Bar;}) ({FOO: {bar: 1 }});  //  Question 12 ( Function  F (){  Function F (){Return 1 ;}  Return  F ();  Function F (){ Return 2 ;}})();  //  Question 13  Function F (){ Return  F ;}  New F () Instanceof  F; //  Question 14  With ( Function (X, undefined) {}) length;

How about it? Isn't it a little tricky? Please think carefully and continue to pull down to see the answer.

 

 

 

 

 

 

 

 

 

1. If you understand what arguments is, you will know what the answer is. In the original question, there are two answers to the question: "object", "array ". The correct answer is: "object". Although arguments can be used as an array downloading, it is not an array, and there is never an array in the return value of typeof.

2. The answer to this question is: an error will be reported. To understand this question, you need to know the role of function. In JavaScript, function has two functions. One is to declare a function. This can be understood. When a function is declared, the function is promoted to the current state.Code(Called function lift); (2) as a function expression, for example:

VaRF =FunctionTest (){}

In this case, test is optional. If test is added, the function will not improve. test is only an internal attribute (F. name) of the current function expression)

3. The answer to this question is: 1. The delete operation in the function does not take effect. In the function, the delete operation cannot delete the form parameter, and no error is reported during deletion. Therefore, X is still X. If you want to delete X, use undefined to cancel its value.

4. The answer to this question is: undifined. The value assignment symbol = has the right combination. When executing the code, first execute the code on the right and then execute the code on the left. So typeof X is undifined, so x = y = undefined

5. The answer to this question is "number ". This is confusing. The function accepts itself as its own parameter and calls it. At this time, it depends on who has a higher priority. Obviously, the parameter has a higher priority, so the actual execution is: Return typeof 1;

6. The answer to this question is "undefined ". I am a little confused about this question. I want to test the usage of this. Although Foo. bar is passed to the function, but when it is actually executed, the context of the function bar is arguments, not Foo, arguemets [0] can be understood as arguments.0 (this is not the case if you write code, but the syntax will be incorrect). In this case, it seems that there is no problem if the context environment is arguemets.

7. The answer to this question is "undefined ". For foo. bar, the context is foo during execution, but when Foo. when bar is assigned to F, the context of F is window, and there is no Baz, so it is "undefined"

8. The answer to this question is: "number ". The syntax of the comma expression tested in this question is not detailed. If you do not understand it, read the documents.

9. The answer to this question is: "1 undefined ". The key to understanding this question is similar to that of question 2nd. If you don't understand it, take a look at the second question.

10. The answer to this question is: "string ". The result of typeof must be a string. So for the string again typeof, it must be "string"

11. The answer to this question is: "undefined ". It's too confusing. It's a pure text game. The parameter Foo = {FOO: {bar: 1} does not exist, so the result is: "undefined"

12. The answer to this question is: 2. The function is upgraded twice and overwritten for the second time. Therefore, F is the function f declared in the Next statement of the Return Statement. Note that F in self-executed function (function f () {}) (); does not improve the function. It is an expression.

13. The answer to this question is: false. During the new process, the constructor returns an instance that represents the object. However, the return value of the function overwrites this instance, so the answer is false. In other words, this is really abnormal ..................

14. The answer to this question is: 2. I first saw this question when I answered the question on Baidu. At first I thought I was wrong. Then I asked about it and asked the website of this abnormal question, then I did not look at the answer. I studied it to find out why. The usage of with is as follows: With (object) {}. In braces, you can reference the attributes of an object instead of using object. ATTR. In this question, with accepts an object, but this object is a function. The function has the Length attribute, which indicates the number of parameters. Therefore, the value returned above is 2.

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.