JavaScript questions: Testing You really mastered JavaScript

Source: Internet
Author: User

Article Introduction: Dmitry Baranovskiy in his blog out of five test questions, testing whether people really understand JavaScript.

Dmitry Baranovskiy in his blog out of five test questions, testing whether people really understand JavaScript. The topics are as follows

First question.

if (! () A "in Window") {
var a = 1;
}
alert (a);

Second question

var a = 1,
b = function A (x) {
X && A (--x);
};
alert (a);

Question number three.

function A (x) {
return x * 2;
}
var A;
alert (a);

Question fourth.

function b (x, Y, a) {
ARGUMENTS[2] = 10;
alert (a);
}
B (1, 2, 3);

Question fifth.

function A () {
alert (this);
}
A.call (NULL);

First question: Answer undefined
The JS function will first handle function declaration, formal parameter, variable declaration (create variable but not assign value, assign value in code execution phase) before executing. This example first handles the variable declaration before the code executes, that is, the parser first does a variable a, but not the function, and cannot assign a value to it. So with the variable A, note that the variable, the global variable is the same as the window's properties (in fact, different, such as the attribute can delete) so the "a" in window is true.
If this is changed to

if (! () A "in Window") {
A = 1;
}

Variable declarations will not be treated preferentially, and the results will be different.
As a contrast can be changed to the following, also according to the above instructions to answer, we try.

Question number two: Answer 1.
Just remember that the name of a named function expression is only valid within the defined function and is determined by the building rules of the ECMAScript scope chain.

Question number three: The answer is a function
As explained in the first question, the functions and declarations and variable declarations are processed first, so a is a function, and var A does not change the assignment, and since then there is no assignment, so a is always a function.

Question Fourth: Answer 10
JS each function has an implied arguments variable, is a class array structure, in turn, records the value of the parameter, and the parameter synchronization changes.

Question Fifth: Answer window

There is nothing to say, by default, window.

Are you all right?



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.