Another JavaScript quiz (code set) _javascript tips

Source: Internet
Author: User
Tags object object vars
You can measure how much you know about this knowledge.
In the title after I refer to the original Bo main article and comment on the topic analysis, we compete to shoot bricks.
The quiz:
1:
1 && 3
2:
1 && "Foo" | | 0
3:
1 | | "Foo" && 0
4:
(1,2,3)
5:
x = {Shift:[].shift};
X.shift (); 3:x.length;
6:
{Foo:1} [0]
7:
[True, False] [+true, +false]

8:
+ + '. Split (') [0]
9:
A:B: c:d: e:f: G:1, 2, 3, 4, 5;
10:
{a:1, b:2} [["B"]]

1
"B" + 45
12:
{A:{b:2}}
13:
(function () {} ())
14:
[1,2,3,4,5] [0..tostring.length]

15:
({} + ' B ' > {} + ' a ')

16:
number.prototype.x = function () {return this = = 123;};
(123). x ();
17:
Array (2). Join ()
18:
Vars:var VARs = VARs;
19:
{foo = 123}
20:
x = 1; (function () {return x; var x = 2;} ())

2
delete [].length;

22:
RegExp.prototype.toString = function () {return this.source};
/3/-/2/;
23:
{break;4;}
24:
' foo ' = = new function () {return String (' foo ');

25:
' foo '. Split (') + []

Analytical:

1: #1. 3:1 is true, and then the && operation continues to execute the expression on the right, resulting in 3
2: #2. ' foo ': logical operator, as above, the expression is successful when it is run to ' foo ', no longer performed | | The expression on the right
3: #3. 1:1 convert to bool to true, direct return, no more down execution
4: #4. 3: Always return the last value
5: #5. 0: When x executes the shift () method, X has the length property and the return value is 0
6: #6. [0]: Two expressions, returning the result of the last expression
7: #7. True: for bool+ operations, the result is 1 or 0 so [true,false][1,0], and this formula always takes the last one, [true,false][0]
8: #8. 6:. Operator precedence is greater than the + + operator, '. Split (')->[' 5 ', ' 2 ']; [0] Get 5;++ 6.
9: #9. 5: Ignore All the preceding: x get: a:1,2,3,4,5 results: 5
#10. SyntaxError. Perhaps you would be surprised that this is not JSON format data, swollen it will be an error? I was surprised at the beginning, but it wasn't JavaScript object, it was a block-level statement execution because there were no assignment statements. {A:1;b:2} is only right when executed as a normal statement. or A={a:1,b:2}
One: #11. "B45": Strings and numeric addition operations, always returning strings
#12. 2: Just two statements block, with question 9th is actually a situation a:b:2, return 2
#13. Undefined: Anonymous null function is executed, automatically returns undefined because no return statement is displayed.
#14. 2: This is interesting. In two parts, first say 0. Tostring. If you add "." To the back of an integer, then JavaScript thinks it's a floating-point point, not the point of the attribute call, and if you dot the floating-point number, then JavaScript thinks it's a property call, because JavaScript can't tell what the user is trying to do at this point. So 0. becomes the call attribute (this is my guess) and then converts 0 to an object and calls its ToString function. If the direct 0.toString is a grammatical error. You can test the 1.1.toString;. 0.toString, etc., can be called. Besides, 0. Tostring.length results: 1, for what is 1 pinch, the length property of the calling function returns the result is the number of parameters of the function, and the JavaScript default number.tostring function has the number of parameters of 1. So, [1,2,3,4,5][1] The result is 2.
: #15. true: {}+ "B" objects and strings are added –> "[Object Object]b", followed by a logical comparison, "B" > "a". Please do not directly test {}+ "B" so you will

Get Nan, why, if this is the first execution {} This statement block, then execute + "B" The result is naturally nan.

#16. False is strictly compared, the left object, the right number, the type does not match.
A: #17. ', ': the array is converted to a string with a join, but an empty array, so the result is obtained.
#18. Undefined: are salted fish, how to roll over, or salted fish. are undefined and, of course, undefined.
A: #19. 123: Block statement execution. With the object of God horse has hits sour yarn relationship.
A: #20. Undefined: It is said that JavaScript will scan the block scope for "Var" Every time a block scope is introduced, and set the variable value with var life to undefined, regardless of whether there was a declaration before, including the function body.
A: #21. False: Delete Hair Ah, this can be deleted? "Delete only returns False when a can is deleted."

Reference: http://perfectionkills.com/understanding-delete/It is clear that some properties of built-in functions cannot be deleted, similar to arguments,

Length, the function's local variable (function () {var a = 1; return delete a}), and so on.

A: #22. 1: First modify the ToString function on the prototype chain of the regular expression, and return the text form of the current regular instance object. The string is then subtracted, which is automatically converted to number for operation. A: #23. The Syntaxerror:break statement can only be placed in loops and switch branch statements: #24. False: Borrow Damian Wielgosik very classical Interpretation (new function () {return String (' foo ');}). ToString ()!= ' foo '
#25. "F,o,o": After the string is converted to an array and then added to a string, you can find two arrays to add and try it, borrow the explanation of Damian Wielgosik

Just consider e.g. [1, 2] + [3, 4] and the how-to-arrays are casted to string.
Related Article

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.