Local Scope and Functions dsdsdsd

Local Scope and Functions dsdsdsd
0

#1

Tell us what’s happening:

Your code so far

function myLocalScope() {
  'use strict';
  
  var myVar= 100;
  console.log(myVar);
}
myLocalScope(myVar);

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

// Now remove the console log line to pass the test

Your browser information:

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

Link to the challenge:


#2

@gabriel.alves,
I would suggest you read the guidelines in the comments.

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

// Now remove the console log line to pass the test <--------------

#3

var is a function scoped keyword. This means that the var created will only be accessible within the the function that it is created in. For your problem, you’re trying to access myVar outside of the function myLocalScope's scope. So the var would come back as undefined since it is not within scope.