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.
Loading...
Related Quiz
- You are designing a car simulation game using JavaScript. Each type of car (e.g., sedan, truck, etc.) has different methods for calculating fuel efficiency. Which object-oriented programming concept would be most appropriate to ensure that each car type can calculate fuel efficiency in its own way, while still inheriting basic characteristics from a general Car class?
- The ________ method is used to parse a JSON string into a JavaScript object.
- Which method is used to handle the successful resolution of a Promise?
- The _______ pattern is used to create an instance of an object with some default values.
- What is the primary use of the for...in loop in JavaScript?