0
0
Javascriptprogramming~20 mins

this in global scope in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of this in Global Scope
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this code in a browser?
Consider the following JavaScript code run in a browser environment. What will be logged to the console?
Javascript
console.log(this === window);
Atrue
Bfalse
Cundefined
DTypeError
Attempts:
2 left
💡 Hint
In browsers, the global object is 'window'.
Predict Output
intermediate
2:00remaining
What does this log in Node.js global scope?
In Node.js, what will this code output when run as a script?
Javascript
console.log(this === global);
Afalse
Btrue
Cundefined
DReferenceError
Attempts:
2 left
💡 Hint
Node.js has a different global object than browsers.
Predict Output
advanced
2:00remaining
What is the output of this strict mode code?
What will this code output when run in a browser console?
Javascript
"use strict";
console.log(this);
AWindow object
Bnull
Cundefined
DReferenceError
Attempts:
2 left
💡 Hint
Strict mode changes the value of 'this' in the global scope.
Predict Output
advanced
2:00remaining
What does this output inside a function in global scope?
What will this code output when run in a browser?
Javascript
function showThis() {
  console.log(this);
}
showThis();
Aundefined
BWindow object
CFunction object
DReferenceError
Attempts:
2 left
💡 Hint
In non-strict mode, 'this' inside a function called in global scope is the global object.
Predict Output
expert
2:00remaining
What is the output of this arrow function in global scope?
What will this code output when run in a browser console?
Javascript
const arrowFunc = () => this;
console.log(arrowFunc() === window);
Afalse
BTypeError
Cundefined
Dtrue
Attempts:
2 left
💡 Hint
Arrow functions do not have their own 'this'.