Can you explain the distinctiveness between utilizing a let in the body of a for loop and a var specifically within the JavaScript for loop? What are the differences in terms of functionality and why?
For instance:
When using let
for (let i = 0; i < 10; i++) {
}
When using var
for (var i = 0; i < 10; i++) {
}
Do these two methods operate similarly or have different mechanisms, and is one more efficient than the other?
Moreover, does this distinction extend to while loops and do-while loops as well?