- 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è
JavaScript: Find the Bug
This JavaScript quiz shows short functions with the kind of bugs that reach code review and production. You will predict the wrong result, name the error and choose the right fix for coercion, this, shallow copies, switch and loop bounds.
Domanda di esempio
Domanda 1 di 10The total should be 15. What does this print instead?
function total(prices) {
let sum = 0;
for (const p of prices) sum += p;
return sum;
}
console.log(total(["5", "10"]));
Mostra la risposta
B. 0510 The prices are strings (typical for form inputs or CSV). 0 + "5" is the string "05", and every later += concatenates. Convert first with Number(p).
Cosa copre questo quiz
- String concatenation instead of addition
- Returning from inside
forEach - Object identity in
includesand=== - Losing
thiswhen passing a method as a callback - Shallow copies,
switchfall-through and off-by-one loops
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.