Is this code wrong? I don't get the result

Tell us what’s happening:

function myLocalScope() {
   'use strict';

  // Only change code below this line
   var myVay;
  console.log('inside myLocalScope', myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log('outside myLocalScope', myVar);

Your code so far


function myLocalScope() {
 'use strict';

// Only change code below this line
 var myVay;
console.log('inside myLocalScope', myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log('outside myLocalScope', myVar);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

Challenge: Local Scope and Functions

Link to the challenge:

What’s wrong? You’ve just shared code without any context.

3 Likes

I made a dumb mistake. it should have been var myVar instead of myVay
sorry :confused:

1 Like

Typos happen to us all. Real-world programming problems :slight_smile:

2 Likes

Instead of var you should use let because they only want to be used inside the function not outside.

1 Like

For the purpose of this challenge, var works as well.

I am not a fan of using var, but it is function scoped so it works. let is block scoped.

2 Likes

You just have to log them out.

1 Like