問題文
A developer writes the following two lines after declaring const settings = { theme: 'dark' }; First: settings.theme = 'light'; Second: settings = { theme: 'light' }; What happens when this code runs?
選択肢
- Both lines throw a TypeError, because a variable declared with const is deeply immutable once the declaration has been evaluated.
- The first line succeeds and the second line throws a TypeError, because const fixes the binding rather than the contents of the object.
- Both lines succeed and settings ends up holding the second object with the theme value set to light.
- The first line throws a TypeError and the second line succeeds, because a whole new object replaces the binding cleanly.