Locan and Global variables

The question about local and global variables https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/local-scope-and-functions/

In this function:

function myTest() {
  var loc = "foo";
  console.log(loc);
}
myTest(); // logs "foo"
console.log(loc); // loc is not defined

If we declare the variable “loc” without the keyword var, const, or let, will “loc” become a global variable?

Yes . When we define variable without the keyword it will have global scope

1 Like