Thrown:
TypeError: Assignment to constant variable.
Is the book incorrect or just mistaken by not using a variable declared with let instead of const? Am I making a mistake somewhere? I tried declaring another variable and using the same method above and it worked as the book explains.
Hi @BrentjFranklin, yes spot on, the reassignment to avengers is indeed a bug in the book; both using let instead and assigning to a new variable are valid fixes (although personally I would avoid reassignments and use const wherever possible).
Another option would be using push() instead which does modify the array it is called on:
That’s what I was thinking. The book didn’t specify that you couldn’t concat a variable declared with ‘const’ and just explained how to do it with the variable it already declared with ‘const’ up the page in the examples. It was just a little unclear, so thank you!
Oops, in the example I put here I forgot the quotes, but I actually have them in the code I ran. It didn’t work when I used ‘const’, but it did concat when I declared the variable using ‘let’.