var vs const vs let code example
Example 1: let vs const
`const` is a signal that the identifier won't be reassigned.
`let` is a signal that the variable may be reassigned, such as a counter in a
loop, or a value swap in an algorithm.
It also signals that the variable will be used only in the block it's defined
in, which is not always the entire containing function.
Example 2: const let var scope
var num = 1;
const num = 2;
let num = 3;
Example 3: var or const in javascript
const myConst='A const does not change.';
var myVar='A var does change.';
var myVar=2;
Example 4: var vs let vs const typescript
let num1:number = 1;
function letDeclaration() {
let num2:number = 2;
if (num2 > num1) {
let num3: number = 3;
num3++;
}
while(num1 < num2) {
let num4: number = 4;
num1++;
}
console.log(num1);
console.log(num2);
console.log(num3);
console.log(num4);
}
letDeclaration();