I was reading the TypeScript Deep Dive and I see that both let and const are block scoped, which is great. Obviously, a const cannot be changed (it is immutable). But why is ReSharper is encouraging me to change as many lets to const as I can? I'm assuming ReSharper thinks there is a performance gain in using const over let? Is there a speed difference between const and let? Is there a different reason to use const? Take the following example:
for (let i = 0; i < this.InputControl.ParentQuestions.length; i++) { const id = this.InputControl.ParentQuestions[i].ParentId; const value = this.InputControl.ParentQuestions[i].ParentRequiredAnswer; if (!formVals[id]) return false; if (formVals[id].toLowerCase() != value.toLowerCase()) return false; } Previously, I had let id and let value but ReSharper asked me to change them to const, which works, but why is it better in this case? Or in any case?
I also found this question on SO, but it talks more about what let and const do, not so much why one is better than the other. It does say to use const as much as possible, but what benefit does that provide?