Preventing Data From Mutation with Freeze Method (javascript mutation)

Murat Umutlu

0 Comment

Algorithms

In JavaScript, we declare variables with CONST when we want to protect it from mutation. But CONST declaration alone is not enough to protect really.

Firstly let’s see data protection with CONST:

As you see there is an alternative way to mutate CONST data. So what about if you really wat your data to be frozen?

You can use Object.freeze for arrays but ES5 can freeze only objects and throws an error. ES6 enables to freeze non-objects, too.

Freeze method also blocks push, pop, shift and unshift methods 🙂

(Visited 1 times, 1 visits today)

Notice: Undefined variable: single_layout in /home/muumdev/public_html/wp-content/plugins/blogsqode-posts/public/single/template-parts/content-single.php on line 376

Post Comments:

Leave a Reply

Your email address will not be published. Required fields are marked *

Close