ES6 - Compare Scopes of the var and let Keywords

Tell us what’s happening:

Hello may I ask why the code doesn’t pass without the let keyword on the second line? I thought a global variable also works in this case.

Your code so far

function checkScope() {
  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;

Your browser information:

Challenge: ES6 - Compare Scopes of the var and let Keywords

Link to the challenge:

1 Like

Hi miltonlee313 and welcome to the freeCodeCamp community! :partying_face:

I am not sure to understand the question. Your code doesn’t pass because they want you do declare a function scope variable and you are using a “global variable”.

If you are asking if in this case the function would return the same value yes that is correct.

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