Hi makenzi.exc,
var: Declares variables with function or global scope and allows re-declaration and updates within the same scope.
let: Declares variables with block scope, allowing updates but not re-declaration within the same block.
var and let create variables that can be reassigned another value.
So we shouldn't use var anymore and use let or const instead.
Refer below example.
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
body { font-family: Arial; font-size: 10pt; }
</style>
</head>
<body>
<script type="text/javascript">
// Using var.
var x = 1;
if (true) {
var x = 2;
console.log(x); // Display 2
}
console.log(x); // Display 2
// Using let.
let y = 1;
if (true) {
let y = 2;
console.log(y); // Display 2
}
console.log(y); // Display 1
</script>
</body>
</html>
Demo
Screenshot

Downloads
Download Sample