What is a closure in JavaScript?
A closure is a function that remembers the variables from where it was created, even after that outer function has returned. Closures let inner functions access outer variables, which is foundational for callbacks and data privacy.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Top JavaScript Interview Questions Every Fresher Should Know
var is function-scoped and hoisted. let and const are block-scoped. const cannot be reassigned. Use let for variables that change, const for those that do not, and avoid var in modern code.
Hoisting moves declarations to the top of their scope. var declarations are hoisted and initialized as undefined. let and const are hoisted but not initialized, causing a temporal dead zone if accessed before declaration.
How JavaScript handles async on a single thread. It processes the call stack, then the microtask queue (promises), then the task queue (setTimeout, events), letting async callbacks run when the stack is clear.
Still have questions?
Browse all our FAQs or reach out to our support team
