3 ms·
The const on b only applies to the object reference to b, and doesn't prevent foo from changing the contents of b. No doubt that's why the test question include
by dang 5y ago
The const on b only applies to the object reference to b, and doesn't prevent foo from changing the contents of b. No doubt that's why the test question includes an array in the first place.
At least I assume that's how const works; I've not used const in JS.
- ornornor 5y agoThat’s possible. In reality, if I ever came across that piece of code and had a bug to fix in it, the first thing I’d do is rename a and b in one scope or the other because it’s just asking for trouble otherwise and it’s not easy to understand what happens to a and b. That’s why I think using this question as a trivia question is bad. But the discussion we’re having about it clearly shows we both know what to look out for, that we’re competent, and is way more interesting than running JS code in our heads. Even if either of us gets the answer wrong, it doesn’t really matter as much as how we got there in my opinion.