0
0
Javascriptprogramming~20 mins

Global execution context in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Global Execution Context Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of variable hoisting in global context
What is the output of the following JavaScript code when run in a browser console?
Javascript
console.log(a);
var a = 10;
console.log(a);
Aundefined\n10
B10\n10
CReferenceError: a is not defined
Dundefined\nundefined
Attempts:
2 left
💡 Hint
Think about how variable declarations are hoisted but assignments are not.
Predict Output
intermediate
2:00remaining
Global object property from var declaration
What will be the output of this code snippet in a browser environment?
Javascript
var x = 5;
console.log(window.x);
A5
Bundefined
CReferenceError
Dnull
Attempts:
2 left
💡 Hint
Consider how var variables relate to the global object in browsers.
Predict Output
advanced
2:00remaining
Output of let in global scope and window object
What will this code print in the browser console?
Javascript
let y = 20;
console.log(window.y);
A20
BReferenceError
Cnull
Dundefined
Attempts:
2 left
💡 Hint
Think about how let differs from var in global scope.
Predict Output
advanced
2:00remaining
Global execution context and function declaration hoisting
What is the output of this code?
Javascript
foo();
function foo() {
  console.log('Hello from foo');
}
foo();
ATypeError: foo is not a function
BReferenceError: foo is not defined
CHello from foo\nHello from foo
Dundefined\nHello from foo
Attempts:
2 left
💡 Hint
Remember how function declarations are hoisted completely.
🧠 Conceptual
expert
3:00remaining
Global execution context creation order
Which of the following correctly describes the order of steps when the JavaScript global execution context is created?
ACode execution phase, then variable and function declarations are hoisted
BVariable and function declarations are hoisted, then code execution phase runs
CCode execution phase runs, then global object is created
DGlobal object is created after code execution phase
Attempts:
2 left
💡 Hint
Think about what happens before the code runs.