JavaScript by Patrik

Function Scope

JavaScript has function scope: Each function creates a new scope.

Variables defined inside a function are not accessible (visible) from outside the function.

Variables declared with varlet and const are quite similar when declared inside a function.

function varFunction() {
  var message = "Hello";   // Function Scope
}
function letFunction() {
  let message = "Hello";   // Function Scope
}
function constFunction() {
  const message = "Hello";   // Function Scope
}

Comments

Leave a Comment

All fields are required. Your email address will not be published.