0
0
Javascriptprogramming~20 mins

Hoisting with let and const in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Hoisting Mastery
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 snippet?

Consider the following JavaScript code:

console.log(a);
let a = 5;

What will be printed to the console?

Javascript
console.log(a);
let a = 5;
Anull
BReferenceError
C5
Dundefined
Attempts:
2 left
πŸ’‘ Hint

Think about the temporal dead zone for let variables.

❓ Predict Output
intermediate
2:00remaining
What is the output of this code snippet?

Look at this code:

console.log(b);
const b = 10;

What will be the output?

Javascript
console.log(b);
const b = 10;
A10
BTypeError
Cundefined
DReferenceError
Attempts:
2 left
πŸ’‘ Hint

Remember how const variables behave before initialization.

❓ Predict Output
advanced
2:00remaining
What is the output of this code snippet?

Analyze this code:

var x = 1;
{
  console.log(x);
  let x = 2;
}

What will be printed?

Javascript
var x = 1;
{
  console.log(x);
  let x = 2;
}
AReferenceError
B2
C1
Dundefined
Attempts:
2 left
πŸ’‘ Hint

Consider the block scope and temporal dead zone of let.

❓ Predict Output
advanced
2:00remaining
What is the output of this code snippet?

Consider this code:

function test() {
  console.log(y);
  const y = 3;
}
test();

What will be printed when test() is called?

Javascript
function test() {
  console.log(y);
  const y = 3;
}
test();
AReferenceError
Bundefined
C3
DTypeError
Attempts:
2 left
πŸ’‘ Hint

Think about the temporal dead zone inside functions with const.

🧠 Conceptual
expert
2:00remaining
Which option correctly explains hoisting behavior of let and const?

Choose the statement that best describes how let and const variables behave during hoisting in JavaScript.

A<p><code>let</code> and <code>const</code> variables are hoisted and initialized with <code>undefined</code> before code execution.</p>
B<p><code>let</code> variables are hoisted and initialized, but <code>const</code> variables are not hoisted at all.</p>
C<p><code>let</code> and <code>const</code> variables are hoisted but not initialized, causing a temporal dead zone until their declaration is reached.</p>
D<p><code>let</code> and <code>const</code> variables behave exactly like <code>var</code> during hoisting.</p>
Attempts:
2 left
πŸ’‘ Hint

Recall the temporal dead zone concept for let and const.