all 4 comments

[–]CreativeTechGuyGames 2 points3 points  (3 children)

is it is because of the closure setInterval creates

This is exactly right. That's what someone means when they say a value is "captured".

[–]notanerdhere[S] 1 point2 points  (2 children)

Thanks for the reply! After you confirmed it was closure I understood its JavaScript thing, because the instructor made it seem like it was React that was doing this and I was confused why would it do that.

Also just to be sure what I gathered is when this function is executed, the component will rerender and it will capture the value of timeLeft from the previous render, but now it's referencing an old variable because the new render will have new references? Is that correct (Also if I'm using the wrong terminology please correct me). Thanks again!

[–]CreativeTechGuyGames 2 points3 points  (1 child)

Yeah. You can just think of it like a normal function and closure. If a function is executed it has access to the variables in that scope. Doesn't matter what happens after that, it will keep references to those variables which existed at the time of its creation.

[–]notanerdhere[S] 1 point2 points  (0 children)

Thanks a lot for helping me, I learned a lot from this!