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 Asynchronous Programming with JavaScript Asynchronous JavaScript with Callbacks Implement a Callback

Crystal Vesely
Crystal Vesely
14,502 Points

Why are we using let instead of const for the variable data?

I am trying to understand let vs const. I thought we’d use const for the variable data since data will not be changing within this function scope. So why are we using let?

1 Answer

Travis Alstrand
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Travis Alstrand
Treehouse Project Reviewer

Nice catch Crystal Vesely !

I'm sure the instructor didn't think too much about it as it wouldn't change anything in this particular example if it were let or const. However, you're correct, using const should be preferable here as it adheres to the principle of using the most restrictive declaration possible, which is a common best practice in modern JavaScript development.

But, they will both work fine in this exact situation. You can definitely use const in your code if you're following along.

Crystal Vesely
Crystal Vesely
14,502 Points

Thanks for clearing that up. I just wanted to make sure I’m on the right thinking path.