If you're creating a new instance of a variable for every scope change/iteration, is it a better practice to use const
over let
if the variable will not change through re-assignment or be redeclared? Does the circumstance of the variable being inside a loop warrant using let
to show intent that there will be multiple variables created with the same name, but in a different scope?
$('.products').each(function() {
const $product = $(this);
// Do something with $product
});
Versus:
$('.products').each(function() {
let $product = $(this);
// Do something with $product
});