For example, say I have his function :
var person = (function(){
var age = "will"
function shoutAge(){
alert(age)
}
return {
shoutAge
}
})()
After this is created I can do :
person.age = 45;
Granted, this is not the age inside the person scope, but this could cause confusion.
I changed it to use const
:
const person = (function(){
var age = "will"
function shoutAge(){
alert(age)
}
return {
shoutAge
}
})()
But I can still add custom properties.
I misunderstood what const was for, you can't reassign the variable, but you can add properties to it fine.
But is there a way to make it un-editable or is that something that shouldn't be done for some reason?