(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?