Quiz di JavaScript: Objects & Copying

Objects and arrays in JavaScript are passed around by reference, which leads to some of the most common bugs. This quiz tests references, const, spread copies, structuredClone(), the JSON trick and Object.freeze().

Medio 10 domande ~6 minuti Superato con il 80% Node.js 22

Scegli una modalità

Stai giocando come ospite: accedi per salvare XP e serie.

Domanda di esempio

Domanda 1 di 10

What does this print?

const a = { x: 1 };
const b = a;
b.x = 2;
console.log(a.x);
Mostra la risposta

B. 2 const b = a copies the reference, not the object. Both names point to the same object, so changing b.x changes what a.x shows.

Cosa copre questo quiz

  • Variables that point to the same object
  • Shallow copies with spread and Object.assign()
  • Deep copies with structuredClone() and the JSON round trip
  • What const and Object.freeze() really protect
  • Comparing objects with ===

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.