whatstheoutput_

#94: const obj, mutated properties

Topic: objects · Difficulty: ★

const obj = { count: 1 };
obj.count = 2;
obj.extra = 3;
console.log(obj.count, obj.extra);

Output

2 3

Why

const only freezes the BINDING — it stops obj from ever being reassigned to point at a different value. It says nothing about the object obj points to, which remains fully mutable: you can change existing properties and add new ones freely. obj.count = 2 changes an existing property, and obj.extra = 3 adds a brand new one; neither is a reassignment of obj itself, so neither violates const.

More objects puzzles

Play today's puzzle →