nerdexam
CIW

1D0-720 · Question #29

What is a closure in JavaScript?

The correct answer is B. A function having access to the parent scope, even after the parent function has closed. Option B is correct because a closure is formed when a function "closes over" variables from its outer (parent) scope, retaining access to those variables even after the parent function has finished executing - this is a core feature of JavaScript's lexical scoping. Option A is…

Client-Side Scripting and Media Queries

Question

What is a closure in JavaScript?

Options

  • AA type of event handler.
  • BA function having access to the parent scope, even after the parent function has closed.
  • CA method used to close a web page.
  • DAn error in JavaScript code.

How the community answered

(14 responses)
  • A
    7% (1)
  • B
    86% (12)
  • D
    7% (1)

Explanation

Option B is correct because a closure is formed when a function "closes over" variables from its outer (parent) scope, retaining access to those variables even after the parent function has finished executing - this is a core feature of JavaScript's lexical scoping. Option A is wrong because event handlers are callbacks assigned to DOM events, a separate concept entirely. Option C is wrong because JavaScript has no built-in mechanism to "close" a web page programmatically in that sense. Option D is wrong because closures are intentional, well-defined behavior, not an error.

Memory tip: Think of a closure like a backpack - when an inner function leaves its parent, it carries the parent's variables with it in that backpack, using them whenever needed later.

Topics

#closures#function scope#lexical scoping#JavaScript

Community Discussion

No community discussion yet for this question.

Full 1D0-720 Practice