Good day viewers,
So before I proceed, whats immutability in programming or in general?
immutability can simply be described in other words as unchangeable. i.e something that shouldn't be changed because it has some superpowers which have made it unchangeable.
So as you can see in the above example, "const operator" has failed us(yes you heard me right i called const an operator and i will write an article very soon on why i think const is an operator(an implicit one to be precise)).
So now how can we avoid "const objects" being changed? because on a good day, we created the object to be immutable!
The answers are:
1.seal method: this method will avoid the addition of property to an object. i.e the limit of and object can never and will never be changed ones the object is sealed but unfortunately, a key-value can be changed.
2.freez method: this method will avoid both a ''key-value'' and ''object-limit'' from being tampered with. i.e you can never change the value of an object-key and you can never add any ''new property'' + delete any property.
Check out the code snippet below
So now, our object is safe.
The next article will be on "either programming reserve keywords are implicit operators or not".
Thanks for stopping by to read,
Written by Emmanuel Onah.