These two are extremely important statements. For few of us who came from languages like Java, it might be shocking. How can object exist without class ? We will deal with that in later sessions when we discuss Object oriented programming.
var has been there since the beginning ,
const are recent additions.
var a = 5; let b = 6; const c = 7; console.log(a); //prints 5 console.log(b); //prints 6 console.log(c); // prints 7
let are similar .
Prefer to use
varexists only for the sake of backward compatibility.
const is used to declare a constant variable ( wow, constant variable huh !!, you get the point)
Lets try the same with
As a good program, it gives error.
Can we change the
let value ?
Ofcourse we can , we can not redeclare it.