Which statement is true regarding function scope in JavaScript?

  • Functions can access variables from outer scopes.
  • Variables declared inside functions have global scope.
  • Variables declared inside functions have function scope.
  • Variables declared inside functions are accessible only within that function's block.
In JavaScript, variables declared inside functions have function scope, meaning they are only accessible within that function. This is important for encapsulation and avoiding variable conflicts. Variables declared outside of functions have global scope, and functions can access variables from outer scopes, but the reverse is not true.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *