Instructions
- 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
- 2. Thoroughly review each solution before proceeding to ensure full understanding.
- 3. Final results will be available after submission to provide insights into areas for further improvement.
- 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
- 5. Once submitted, responses are final, so ensure you’re confident in your answers.
- 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.
All Problems
Question
Action
What is a lexical environment in JavaScript?
What is the key feature of a closure?
What will the following code output? function outer() { let x = 5; return function inner() { return x + 2; }; } const result = outer(); console.log(result());
Can closures access global variables?
What will this code print? function counter() { let count = 0; return function() { count++; return count; }; } const increment = counter(); console.log(increment()); console.log(increment());
Why do closures maintain access to outer variables after the outer function finishes execution?
What will this code log? let name = "Alice"; function greet() { console.log(name); } greet();
What happens if a closure function is executed multiple times?
What is one common use of closures in JavaScript?
What does the following code print? function outer() { let secret = "hidden"; return function() { return secret; }; } let reveal = outer(); console.log(reveal());