$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #249

Which fix removes the bug?

const cfg = Object.freeze({ db: { host: 'x' } });
cfg.db.host = 'y';
console.log(cfg.db.host); // expected x
  1. Freeze the nested objects too
  2. Use Object.seal instead
  3. Declare cfg with let
  4. Add 'use strict' at the top
Object.freeze is shallow: cfg itself is frozen, but cfg.db is an ordinary object that can still change. Freeze it as well (a deep freeze).
Play Problem Solving ▸