What is a typical interview question type regarding JavaScript closures?
Question 3
What is printed by the following code?
```javascript
for (let i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 100);
}
```
Question 4
Why is understanding closures essential for JavaScript developers?
Question 5
What is the behavior of `var` in a for-loop related to closures?
Question 6
What does the following code create?
```javascript
function createElementCreator(type) {
return function() {
return document.createElement(type);
}
}
const createDiv = createElementCreator('div');
const createSpan = createElementCreator('span');
const divEl = createDiv();
const spanEl = createSpan();
```
Question 7
What is a common use case for closures in modern JavaScript?
Question 8
Why do `let` variables behave differently in loops involving closures compared to `var` variables?
Question 9
In the provided code example, why does `newFunc()` print 29?
Question 10
How do closures relate to higher-order functions?
Question 11
Why are variables retained in memory in a closure?
Question 12
What will the following code example print and why?
```javascript
function outer() {
let age = 29;
function inner() {
console.log(age);
}
age = 30;
return inner;
}
const innerFunc = outer();
innerFunc();
```
Question 13
Why might closures be less critical in modern JavaScript with the advent of modules?
Question 14
What crucial concept do closures integrate with in JavaScript?
Question 15
What is printed by the following code?
```javascript
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 100);
}
```