Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Array Iteration Methods Array Manipulation Remove Array Items with filter()

Why use let for sNames?

Why was sNames declared using let instead of const before changing it to filter? The variable is not reassigned when using Array.push, right?

2 Answers

Doron Geyer
seal-mask
.a{fill-rule:evenodd;}techdegree
Doron Geyer
Full Stack JavaScript Techdegree Student 13,897 Points

Hey Tom McLean surprised you never got a response. You were indeed correct. For anyone else who has this same question, const would have been preferable here. He originally used let because he wanted to change the array. Later in the same course he updates it to const when he changes from forEach to filter.

Nils Kriedner
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Nils Kriedner
Full Stack JavaScript Techdegree Graduate 30,933 Points

I just had the same comment in mind when watching the video...

The convention is to declare arrays with 'const'.

By by changing the content of an array (for example using push()) the array itself is not reassigned. So there is no need to use 'let' here.