"var" works similarly to "let" except "let" is block scoped, which means it only exists within the block of code that it was created in. Whenever we use "var" to declare a variable, that variable is now hoisted. You may ask what does it mean to be hoisted? Simply put, hoisting means that variable declaration occurs before execution. Here's an example if my explanation wasn't clear.
So I made a function called "exampleVar" and it just has a for loop with nothing inside of it with a conditional if/else statement, which will log in the console based on whether or not "i" has been defined. If you notice, I have used var to declare "i" which will hoist that variable to be available inside of the containing function. In other words, the variable "i" is initialized at the top of "exampleVar", but its value is not assigned until the for loop. Now let's look at what happens if I use "let" instead of "var".