Are you ready?
10 questions to solve
- This quiz goes to full-screen once you press the Start button.
- At the end of the quiz, you are able to review all the questions that you answered wrong and see their explanations.
There is no typo in the code.
(function() {
console.log('Hello World!');
});
()
, hence it's body doesn't execute. This means that nothing is logged in the console, which goes with choice (B). For more info, refer to JavaScript Functions — IIFEs.callee
property of the arguments
object available inside a function contains a reference to the function itself, and can therefore be used to recursively call it. This goes with choice (B). For more info, refer to JavaScript Functions — arguments.callee
.console.log(this === window);
this
as used in the global context returns back the window
object. Hence, this === window
evaluates to true
, and thus the correct choice is (A). For more info, refer to JavaScript Functions — this
.var x = 10;
var f2 = f;
var obj = {
x: 20,
f: f2
}
console.log(f());
console.log(f2());
console.log(obj.f());
function f() {
return this.x;
}
Let's go step-by-step. First, a global variable x
is created with the value 10
. Next another variable f2
is created with the value f
, which is a function accessible at this stage via functional hoisting. Next up, an object obj
is created with a property x
set to 20
and a property f
set to f2
.
In the first log, f()
gets executed with this.x
resolving down to the global variable x
. Likewise, we get 10
logged. The second log is similar to the first log, hence we get another 10
logged. The last log calls obj.f()
, likewise this.x
inside the function resolves to obj.x
which is 20
. Hence, 20
gets logged.
Altogether, we get 10
, 10
and 20
logged. This goes with choice (C). For more info, refer to JavaScript Functions — this
.
function() {
}
this
.Hoisting
.IIFEs
.var sum = function localSum(a, b) {
return a + b;
}
console.log(typeof localSum);
typeof localSum
above returns 'undefined'
, and this goes with choice (A). For more info, refer to JavaScript Functions — Named function expressions
.