Advanced Patterns

Preview — 3 of 10 questions

What will be the output of the following code?

javascript
function foo() {
  console.log(this);
}

foo();
Awindow (in browsers) or global (in Node.js)
Bundefined
Cnull
DReferenceError

Which of the following is not true about JavaScript closures?

javascript
function outer() {
  let count = 0;
  return function inner() {
    count++;
    return count;
  };
}
AA closure allows a function to remember variables from its outer scope.
BClosures help in creating private variables.
CA closure is created when a function is defined inside another function.
DClosures cannot access variables declared with let or const.

What will be logged by the following code?

javascript
let a = {};
let b = a;

console.log(a == b, a === b);
Atrue, true
Btrue, false
Cfalse, true
Dfalse, false

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.