when to use const,let and var code example

Example 1: var let const javascript

Const vs Let vs Var

const pi = 3.14

pi = 1 
cannot do this becuase with const you cannot change the value

_____________________________________


Let --> is block level 

for(let i = 0; i < 3; i++) {
console.log(i) --> it will console here
}
console.log(i) ---> Not here


---------------------------------------

Var is for variables available to the entire function 


for(var j = 0; j < 3; j++) {
console.log(j) --> it will console here
}
console.log(j) ---> it will console here

Example 2: why use const and not let?

const only prevents re-assigning, it doesn't make the entire object immutable. ... It's useful to use const instead of let , because it prevents you from accidentally overwriting variables