How does JavaScript support lexical scoping?

  • By creating global variables
  • Through the use of the 'var' keyword
  • By nesting functions
  • By using block-level scoping with 'let'
JavaScript supports lexical scoping by allowing functions to access variables defined in their containing (enclosing) functions. This means that inner functions can "see" and use variables from outer functions, creating a chain of scope. This is achieved by nesting functions. Modern JavaScript also introduced 'let' for block-level scoping.
Add your answer
Loading...

Leave a comment

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