Some javascript some of the topics of analytic _javascript techniques

Source: Internet
Author: User
http://perfectionkills.com/javascript-quiz/
Here are my thoughts on these topics, some understanding of myself. If you have any different opinions or opinions, please take the bricks.
Copy Code code as follows:

(function () {
return typeof arguments;
})();

This topic is relatively simple, as long as we do not think arguments is array, it can be.
Return is object.
Copy Code code as follows:

var f = function g () {return 23;};
typeof G ();

Flipping through aiming's book, you'll find that there's an explanation of the function in it, and a few ways to create it, and this trap, it appears in a number of topics below. Be careful.
Return is undefined.
Copy Code code as follows:

(function (x) {
Delete x;
return x;
}) (1);

The Javascript delete is not the object that was introduced or pointed to. But the object itself.
/*
Information
Delete operator
Deletes an attribute from the object, or deletes an element from the array.
Delete expression
The expression parameter is a valid JScript expression, usually a property name or an array element
Therefore, the change of the formal parameters here is not related to him.
*/
On the specific analysis of delete, there are garden friends gave the topic part of the original explanation, careless did not go to see, hehe
http://perfectionkills.com/understanding-delete/
Returns 1.
Copy Code code as follows:

var y = 1, x = y = typeof x;
X

This part has a little trap. Oh.
x= Undefined, you know. Then typeof X, which is actually typeof "undefined". Oh
The return, of course, is string.
Copy Code code as follows:

(function f (f) {
Return typeof F ();
}) (function () {return 1;});

Well, the traps come again. haha. What is this f? It has nothing to do with formal parameters, and you can't get it.
So, there is no change in formal parameters.
So, return number.

Copy Code code as follows:

var foo = {
Bar:function () {return this.baz;},
Baz:1
};
(function () {
Return typeof Arguments[0] ();
}) (Foo.bar);

This place. The main consideration is the context of this. The incoming is Foo.bar, not his parent.
So, return to undefined.

Copy Code code as follows:

var foo = {
Bar:function () {return this.baz;},
Baz:1
}
typeof (F = foo.bar) ();

With the above topic, the topic can be understood.
So, return to undefined.

Copy Code code as follows:

var F = (function f () {return ' 1 ';}, function g () {return 2;}) ();
typeof F;

Here, the exquisite is () the return. () is the last one returned.
Returns number.

Copy Code code as follows:

var x = 1;
if (function f () {}) {
x + + typeof F;
}
X

If the thing in that is definitely enforceable. Because he is an actual existence (object). Objects that are not null|underfined can be continued under if. However, the same principle as the above, F, but it does not exist.
So return 1undefined.

Copy Code code as follows:

var x = [typeof x, typeof y][1];
typeof typeof X;

Here, typeof y, undefined. Then, typeof typeof undefined => vtypeof "undefined"
Returns "string".

Copy Code code as follows:

(function (foo) {
return typeof Foo.bar;
}) ({foo: {bar:1}});

Oh, here is a small trap, if see too fast easy to go in.
Under the simple description, var fo = {foo:{bar:1}}; Function (foo) {}) (FO);
Return typeof Foo.bar ==> return typeof Fo.bar
So return to "undefined".

Copy Code code as follows:

(function f () {
function f () {return 1;}
return f ();
function f () {return 2;}
})();

This topic is about the compiler's parsing of function. It's okay to return. When he sees return as only a string, the compiler has parsed all the function. is different from the var f = function () {}.
So, it will return 2.

Copy Code code as follows:

function f () {return F;}
New F () instanceof F;

This place is not understood enough, the explanation that the bottle gives seems to look past
The new F () Gets the f itself, not a new object, so it's not an instance of F.
So, return false.

With (function (x, undefined) {}) length;
With this piece, if I see the with also as a function (as I imagined alert).
The length, then, is the formal parameter of the with.
Returns 2.
All right. It seems that a lot of JS problems, in fact, still need to comb under. Aiming Big book, about this part of the explanation is very strong. Can get people to bypass some traps and problems. The rest is a few of their own tests.
These topics can not fully reflect a person's JS ability, but at least let people know how the compiler is to deal with JS

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.