You think you know a lot about javascript?

Source: Internet
Author: User

(Please understand the improper translation)

Source: http://www.ido321.com/914.html

Here are 5 small scripts that will help you really understand the JavaScript core – closures and scopes. Before the console executes, try to answer what pops up in each case, and then you can create a test file to check your answers.

Are you ready?

1.

   1:if (! ( "a"  in window) {
   2:     var a = 1;
   3:  }
   4:  alert (a);

2.

   1:var a = 1,
   2:     function A (x) {
   3:         x && A (--x);
   4:     };
   5:  alert (a);

3.

   1:function A (x) {
   2:     return x * 2;
   3:  }
   4:var A;
   5:  alert (a);

4.

   1:function b (x, Y, a) {
   2:     arguments[2] = ten;
   3:     alert (a);
   4:  }
   5:  B (1, 2, 3);

5.

   1:function A () {
   2:     alert (this);
   3:  }
   4:  a.call (null);

My pre-Test answers are: Undefined, 1, not known, 10, null

At the end of this article, do you dare to leave your test before reading the answer?

Correct answers: 1, undefined 2, 1 3, function A (x) {return x * 2} 4, 10 5, [object window]

Source: http://dmitry.baranovskiy.com/post/91403200

You think you know a lot about javascript?

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.