let and const cannot be declared more than once *in the same block.
So if you accidentally name two lets or const the same in the same block, it gives an error.
If you declare an existing let inside a different block, it is allowed but creates, not redefines, a new let.
const cannot be updated.
If an object is const, the structure of the object cannot change but its properties can change.
const person={name:”Arjun”, age:26};
person.age=27;
console.log(person); //shows age 27.
If you want the properties of an object to be unchangeable:
const arjun=Object.freeze(person);
arjun.age=27;
console.log(arjun);//shows age 26
let and const
let and const
*can’t be declared more than once
*const properties can change
*Object.freeze
*Object.freeze
No comments:
Post a Comment