Function Scoping

When you define a function, it creates a lexical scope.

A lexical scope or static scope in JavaScript refers to the accessibility of the variables, functions, and objects based on their physical location in the source code.

Any value defined within the function will not be accessible by code outside the function.

function myFunction () {
  var num = 4;
}

console.log(num);