Why does this use let and var together? Was I (not a modern js expert) wrong to think var is considered obsolete? Is it because OP wanted to use var's scoping rules?
It's almost certainly from copy-pasted code from other sources. The Perlin Noise section at the top is not original code at least - though I can't find an original source.
if(checkForSomething()) {
let foo = 2;
} else {
let foo = 3;
}
console.log(foo); // won't work
But:
if(checkForSomething()) {
var foo = 2;
} else {
var foo = 3;
}
console.log(foo); // will work
That said, I religiously avoid "var" and just declare the variable beforehand with "let" because there are too many other gotchas with var. Less debugging headaches. And use "const" religiously as well, like C++ people do.
It's not really any different if you keep in mind that foo is a reference here, and so that's what const applies to. The equivalent in C++ would be a const pointer to a non-const object.