Re:Deep-copying in JavaScript
by kevincennis on Thursday January 25, 2018 @02:37PM
(#16233851)
That's irrelevant. Look, same example but with an object.
[ Parent
| on HN ]
Another way to think about it is that you just get a new reference to the same object, inside foo you are changing what 'a' refers to instead of what 'b' refers to. Using 'let' to declare 'b' is not necessary and using 'const' works just as well.
$ node
> const b = { bar: 'baz' }
> function foo(a){ a = {beep: 'boop'}; }
> foo(b)
> console.log(b)
{ bar: 'baz' }
>
Re:Deep-copying in JavaScript
by lowkeyokay on Friday January 26, 2018 @02:48AM
(#16237602)
I thought this was just a matter of scope. a declared outside of the function is not the same as the one declared as a parameter.