MV "var" vs "let" variables inside a for loop?

What exactly is the difference between these 2?

JavaScript:
for(var i = 0; i <= 5; i++)

for(let v = 0; v <= 5; v++)

Also, in my own personal RMMV JS plugin, using var in a for loop like the above works like it should but using let in a for loop like above iterates much more and gives too much and too weird results.
var persist afterward (can even become a global variable)
let doesn't

Here is a quick test in the browser console.
Screenshot_1092.jpg
That's what I had thought. But the results for my plugin wee weird when I had changed from var to let.
Hi! There are 3 common ways to declare a variable; var, let, and const.

The difference is how the scoping works:
  • var is function scoped
  • let and const are block scoped.
Example code:
JavaScript:
function scopeTest(){
    //block
    {
        //function scoped, can be accessed outside this block
        var a = 1;
       
        //block scoped, cant be accessed outside this block
        let b = 2;
        const c = 3;
       
        console.log(a, b, c);
    }
   
    console.log(a);
    console.log(b, c);
}

scopeTest();

Generally you want to use let and const over var.
Someone correct me if i am wrong, but let and const are ES6 feature, while RMMV does not support ES6?
Since you code for RMMV, i remember reading a thread here that said you can use let and const if you include "use strict". How about you try it then tell us if the weird result still persist?
If you need to know more I wrote more about it in this topic
MV support ES6 while I use it for my own plugins for menu customiser
and Universal Level System and some others.

var is more widely use if it needs the check, let is to block inside the
function, const(ant) is that it constant check for it.

but Soulrender explained it really nicely in the other thead for those difference.
I actually think that var is global, this.var is inside the function, let is inside the brackets and const is inside the brackets and cannot be changed. What do you guys say?

Original thread: https://forums.rpgmakerweb.com/threads/var-vs-let-variables-inside-a-for-loop.143434/