freeCodeCamp/guide/english/certifications/javascript-algorithms-and-d.../basic-javascript/local-scope-and-functions/index.md

626 B

title
Local Scope and Functions

Local Scope and Functions

Local scope means that the variable is available within a certain area. In the case of this exercise, myVar is only available within the function, and not anywhere outside.

Here is the basic code solution to create a local myVar variable.

function myLocalScope() {
  var myVar;
  console.log(myVar);
}
myLocalScope();

The variable only exists in the function. Outside the function, it is non-existent.