GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing it.javascript.info — Oggetti costanti?

  • Tutorial
  • Il linguaggio JavaScript
  • Oggetti: le basi
  • Oggetti
torna alle lezioni
Questo materiale è disponibile nelle seguenti lingue: . Per favore, aiutaci con la traduzione in Italiano.

Oggetti costanti?

importanza: 5

E’ possibile modificare un oggetto dichiarato con const? Cosa ne pensi?

const user = {
  name: "John"
};

// does it work?
user.name = "Pete";

Certo, funziona senza problemi.

La keyword const protegge la variabile solo da riassegnazioni.

In altre parole, user memorizza un riferimento all’oggetto. Questo non può cambiare. Ma l’oggetto contenuto non ha nessun vincolo.

const user = {
  name: "John"
};

// funziona (abbiamo cambiato una properietà dell'oggetto)
user.name = "Pete";

// errore (abbiamo cercato di cambiare tutto valore in un colpo solo)
user = 123;
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.