Challenge - 5 Problems
Let Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of let variable in block scope
What is the output of this code?
Javascript
let x = 10; if (true) { let x = 20; console.log(x); } console.log(x);
Attempts:
2 left
💡 Hint
Remember that let variables are block scoped.
✗ Incorrect
The variable x declared inside the if block is different from the one outside. Inside the block, x is 20, outside it remains 10.
❓ Predict Output
intermediate2:00remaining
Reassignment of let variable
What will be the output of this code?
Javascript
let count = 5; count = 10; console.log(count);
Attempts:
2 left
💡 Hint
Variables declared with let can be reassigned.
✗ Incorrect
The variable count is declared with let and then reassigned to 10, so the output is 10.
❓ Predict Output
advanced2:00remaining
Temporal Dead Zone with let
What error does this code produce?
Javascript
console.log(a); let a = 3;
Attempts:
2 left
💡 Hint
Variables declared with let are not hoisted like var.
✗ Incorrect
Accessing a let variable before its declaration causes a ReferenceError due to the temporal dead zone.
❓ Predict Output
advanced2:00remaining
let in for loop scope
What is the output of this code?
Javascript
for (let i = 0; i < 3; i++) { setTimeout(() => console.log(i), 0); }
Attempts:
2 left
💡 Hint
Each iteration has its own block scope with let.
✗ Incorrect
Using let in the loop creates a new i for each iteration, so the logged values are 0, 1, and 2.
🧠 Conceptual
expert2:00remaining
Why use let instead of var?
Which of the following is the main advantage of using
let over var?Attempts:
2 left
💡 Hint
Think about how variable scope affects code reliability.
✗ Incorrect
let is block scoped, which helps avoid bugs caused by var's function or global scope, especially in loops and conditionals.