JavaScript ES3 Small Test

Source: Internet
Author: User

First, restudying

Do the problem, always can have restudying experience. This set of questions is a year old, older,

http://perfectionkills.com/also has a set of http://perfectionkills.com/javascript-quiz-es6 relatively new ES6 related.

In this page there are 14 ECMAScript related questions, I tried to answer the wrong 6 questions, some knowledge, feel will, others say can certainly understand, but do not necessarily do the problem, is because the master is not deep enough, or memory error, and so on, below to analyze.

Second, analyze the test center and principle of each problem

Each knowledge point will not be explained in detail, some are donuts, some will give a reference link.

1, test centers: typeof and Arguments
(function() {    returntypeof  arguments;  }) ();

Analysis: The TypeOf return value has "string"/"number"/"Undefined"/"boolean"/"function"/"Object". Learn more.

And arguments is an array of classes, not a real array, so it is clear that the TypeOf return value is "Object". Learn More

2. Test Center: Named function Expression Nfe "I answered wrong."
var function Return typeof G ();  

Analysis: Var f=function g () {} is a named function expression.

typeof g () returns the typeof value of the result after the G function call.

When I find the variable g on the scope chain, I can't find it, so I get an error: G is not a function.

So the correct answer is D.

specification: A named function expression name (identifier) is valid within the scope of the function body and cannot be overwritten. Learn More

3, test Center: Delete "I answered wrong"
  (function(x) {    delete  x;     return x;  }) (1);

Immediately executes the function corresponding to the variable object has an X value for the incoming 1, equivalent to the Var declaration, so it cannot be deleted.

Delete x returns FALSE. Return x returns a value of 1.

So the correct answer is 1 .

Remember that the deleteoperator cannot delete the variable and cannot delete the parameter, which is used to delete the attribute configurable to true on the object to learn more

4. Test Center: Variable declaration, execution context
var typeof x ; x;

Analysis: Var y=1,x=y=typeof x;

The first step: y=undefined,x=undefined;

Step two: typeof x returns the "undefined" string, assigns the string to the Y variable, and assigns the value to the X variable, so the last X and Y values are the string "undefined". Learn More

5. Test-Center: Priority
(function  f (f) {    returntypeof  f ();}) (functionreturn 1; });

Analysis: Function call () priority is higher than TypeOf priority

The parameter passed in Ief is a function that, after the call, executes the function to get the result number 1, and typeof 1 returns "Numbers" so the answer is "#". Learn More

6. Test Center: this
  var foo = {    functionreturnthis. Baz;},    1  };  (function() {    returntypeof Arguments[0] ();  }) (foo.bar);

Analysis:

Foo is an object in which there is an attribute Baz, a method bar. Passing a parameter in the Ief Foo.bar,foo.bar is a function,

When called, the function executes first, returning a this.baz. At this point, this points to the Window object, Window.baz does not exist, so returns undefined, and typeof undefined returns "undefined". Learn More

7. Test Center: this
var foo = {    functionreturnthis. Baz;},    1  }   typeof (f = foo.bar) ();

Assign the Foo.bar property to F, at which point F is a function, and after the call this window,window.bar does not exist, returning undefined,typeof undefined returns "undefined".

8, test center: comma operator "I'm wrong."
var f = (functionreturnfunctionreturn 2;}) (); typeof F;

This topic examines the comma operator.

F is an immediately executed expression, and the value of the comma expression is the last expression function g () {}, so calling the G function immediately returns 2,typeof 2 is "number".

The comma expression evaluates the value of the expression from left to right, and finally takes the rightmost one. Learn More

I took the comma operator to the left, so I made a wrong answer.

9.Pits"I answered the wrong question."
var x = 1;   if (function  f () {}) {    typeof  F;  }  x;

Analysis: function f () {} is a variable declaration, we usually write code is not possible to put a function declaration in the IF statement, but test the if to put a function declaration, the condition is true content will be executed.

While Typof F goes to find F, it cannot be found in its scope, so typeof F returns the "undefined" string, so x+= "undefined" the value of the final x is "1undefined".

10. Test Centers
var x = [typeoftypeof Y][1]; typeof typeof X;

Analysis: Typefo returns itself as a string, again typeof "string". This is an opportunistic thinking.

11.
(function(foo) {    returntypeof  foo.bar;   1}});

Analysis: An object literal passed in Ief has an attribute Foo,foo value is an object that contains a bar property. When called, gets the bar property in the Parameter object, and does not have this property, so return undefined,typeof undefined returns "undefined".

12. Test Center: Function declaration pre-parse "I answered wrong."
(function  f () {    functionreturn 1;}     return f ();     function return 2;}  }) ();

Inside the F function that executes immediately, declaring an F value in the variable declaration phase is a function declaration that is overwritten by a subsequent function declaration, so the value of F is function f () {return 2;}

I'm mistaken, the declaration of a variable declaration stage function is assigned directly, so the answer is 2. Learn More

13, Test Center: instanceof "I answered wrong"
function return  Newinstanceof F;

constructor function f () {

Return f;//Returns a value of F, the scope chain looks up, can find f=>function f () {return F;} because F is not a base type, it returns F.

}

So the result of the new F () call is the F function itself. So now the question becomes whether F instanceof F is true or false.

function A () {} is an instance of a function, and the A.prototype property is not found on the prototype chain of a, so instanceof returns FALSE.

Learn More

14. Test Center: With statement
 with (function(x, undefined) {}) length;

Analysis: Equivalent to getting the number of actual arguments for anonymous functions in with

The author starof, because the knowledge itself in the change, the author is also constantly learning and growth, the content of the article is not updated regularly, in order to avoid misleading readers, convenient tracing, please reprint annotated source: http://www.cnblogs.com/starof/p/6816474. HTML has a problem welcome to discuss with me, common progress.

JavaScript ES3 Small Test

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.