Closed vikrantuk closed 3 years ago
That's not re-assigning the BLUE special
... that's mutating the contents inside the object that the BLUE special
points to, by virtue of a copied reference to that object. Those are entirely different things. There is absolutely no way to access the shadowed BLUE special
as a lexical identifier, meaning there's no way to re-assign it.
@getify Thanks for the clarification..
Please type "I already searched for this issue": I already searched for this issue
Edition: (1st or 2nd) 2nd
Book Title: You Don't Know JS Yet: Scope & Closures
Chapter: The Scope Chain
Section Title: Copying Is Not Accessing
Problem: Book states that-
Another "But...!?" you may be about to raise: what if I'd used objects or arrays as the values instead of the numbers (112358132134, etc.)? Would us having references to objects instead of copies of primitive values "fix" the inaccessibility?
No. Mutating the contents of the object value via a reference copy is not the same thing as lexically accessing the variable itself. We still can't reassign the BLUE(2) special parameter.
But on running this code in chrome browser:
Generates output:
Here special from lookingFor function gets changed to update value of a to 23. Which goes against stated lines in book: "We still can't reassign the BLUE(2) special parameter."