0

"Const variables allow an object sub-properties to be changed but not the object structure."

What means "object structure"? Because this code is compiling:

const numbers = [1, 2, 3]; // inferred to type number[]
numbers.push(4); // no error

May anyone give a compiling error of a sentence after declaring the const "numbers" in my example?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • 1
    The sentence is wrong. The object structure sure can be changed. The restriction is that the variable name can't be reassigned to point to an altogether different object. `const someVarName = ...; someVarName = somethingElse` is forbidden, that's all – CertainPerformance Jun 11 '22 at 23:02
  • Oh ok, it calls "object structure" to REDEFINE the const. –  Jun 11 '22 at 23:04
  • @CertainPerformance, yes, thanks I realized that after checking some examples. –  Jun 11 '22 at 23:05

0 Answers0