0
0
Javascriptprogramming~20 mins

Variable declaration using let in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Let Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
A20\n20
B10\n20
C20\n10
D10\n10
Attempts:
2 left
💡 Hint
Remember that let variables are block scoped.
Predict Output
intermediate
2:00remaining
Reassignment of let variable
What will be the output of this code?
Javascript
let count = 5;
count = 10;
console.log(count);
A5
B10
Cundefined
DReferenceError
Attempts:
2 left
💡 Hint
Variables declared with let can be reassigned.
Predict Output
advanced
2:00remaining
Temporal Dead Zone with let
What error does this code produce?
Javascript
console.log(a);
let a = 3;
AReferenceError
BSyntaxError
CTypeError
Dundefined
Attempts:
2 left
💡 Hint
Variables declared with let are not hoisted like var.
Predict Output
advanced
2: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);
}
A0\n1\n2
B3\n3\n3
Cundefined\nundefined\nundefined
D0\n0\n0
Attempts:
2 left
💡 Hint
Each iteration has its own block scope with let.
🧠 Conceptual
expert
2:00remaining
Why use let instead of var?
Which of the following is the main advantage of using let over var?
A<code>let</code> variables are hoisted and initialized with undefined.
B<code>let</code> variables can be redeclared in the same scope without errors.
C<code>let</code> variables are globally scoped by default.
D<code>let</code> variables are block scoped, preventing unexpected behavior in loops and conditionals.
Attempts:
2 left
💡 Hint
Think about how variable scope affects code reliability.