Can you really declare a variable twice? I'm kinda confuse about this lesson

function checkScope() {
  let i = 'function scope';
  if (true) {
    let i = 'block scope';
    console.log('Block scope i is: ', i);
  console.log('Function scope i is: ', i);

  return i;

Challenge: Compare Scopes of the var and let Keywords

Link to the challenge:

You aren’t declaring it twice, it’s two different variables, the lesson is teaching scope. The curly brackets denote a scope here: inside the if block, you can declare variables that just live inside the scope.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.