- Esecutori
-
Impara
Impara Python Esempi eseguibili, NumPy, pandas e altro Impara l'IA / Machine LearningReti neurali, ML e LLM da zero Impara C e C++ Puntatori, memoria, STL e C++ moderno Impara C#Fondamenti, OOP, LINQ, async ed esercizi .NET Impara MatplotlibGrafici a linee, barre, dispersione e torta con visualizzatori Impara RustOwnership, trait, gestione degli errori e thread Impara GoSlice, interfacce, goroutine e canali Algoritmi Python Ricerca, ordinamento, ricorsione e visualizzazioni O(n) Algoritmi C e C++ Confronta le implementazioni in C e C++ Programmazione per bambini Impara a programmare giocando!
- QuizNuovo
- SfideNuovo
- Per docentiNuovo
- Aggiornamenti
- Offrimi un caffè
Quiz di JavaScript: Closures
This JavaScript closures quiz is built from interview questions. You will trace counters and function factories, solve the classic loop and setTimeout puzzle and see how closures keep data private.
Domanda di esempio
Domanda 1 di 10What does this print?
function makeCounter() {
let count = 0;
return () => ++count;
}
const next = makeCounter();
next();
next();
console.log(next());
Mostra la risposta
D. 3 The returned function keeps a link to count even after makeCounter has finished. Each call increases the same count, so the third call returns 3.
Cosa copre questo quiz
- A function remembers the variables of the scope where it was created
- Each call to a factory function makes a new, separate closure
- The
varin a loop withsetTimeoutpuzzle and its fixes - Closures capture variables, not values
- Private state, currying and
once()
Domande frequenti
Serve un account?
No. Chiunque può giocare. Accedi per salvare XP, serie, badge e cronologia.
Posso rifarlo?
Sì. Il tuo miglior punteggio resta salvato, e domande e risposte vengono mescolate ogni volta.