ES6 - Compare Scopes of the var and let Keywords

Tell us what’s happening:
Hello, I got through the answer with help online. What I am confused on if (true) logic.

Why do we have to place if (true) within the function?

Thank you!

Your code so far

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: ES6 - Compare Scopes of the var and let Keywords

Link to the challenge:

It’s just so that it console logs what we want. if (true) is always true

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