let has block scope, i.e. it’s scoped to the block in which it’s declared in. For example, in the case of an if statement:
if (num===0) {
let message = “nothing”;
}
In this example, it’s only accessible to the if block.
var has global scope, i.e. it’s accessible throughout the program.
In the case of the above if statement it will not have block scope if declared using var and as such will be accessible throughout the program.
This is a quick explanation of the difference between the two. Additional details in a future post or feel free to comment below. 🙂
