×

javascript · level 3 · unit 4 · lesson 3

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

const locks the label, not the box. Freezing locks the box.

const settings = { } stops you pointing settings at a new object, but anyone can still it: settings.theme = "dark" works. When two parts of a program share that object, one quiet change surprises the other.

makes it : in strict mode, changing, adding or deleting a property throws a TypeError. Beware: freezing is . Objects nested inside stay changeable unless you freeze them too.

const settings = Object.freeze({ theme: "light", sizes: [12, 14] });
try {
  settings.theme = "dark";
} catch (error) {
  console.log(`${error.name}: settings are frozen`);
}
settings.sizes.push(99);
console.log(settings.theme, settings.sizes, Object.isFrozen(settings.sizes));

Object.isFrozen(x) tells you whether x itself is frozen.