Immutable variables

Freedom is an open window, loosely typed variables is anarchy

As every programmer had felt, the ease of loosely types variables become very fast an undamaged mess. And still, almost no one is using the different option JavaScript provide to manage the unmanageable.

A. Freeze 

Freeze makes an object immutable, so you cannot add, delete or change its properties. But it does only a shallow freeze, so you still can change arrays on objects inside the frozen one.

let o = {a:'a',arr:[],obj:{}};
Object.freeze(o);
Object.isFrozen(o) == true;

o.a = 'a1';
o.a == 'a';

o.arr = 'a';
o.arr == [];

o.arr.push('1');
o.arr == ['1'];

o.obj = 'a';
o.obj == {};
o.obj.x = 'x';
o.obj == {x:'x'}

o.d = 'd';
o.d == undefined;

delete o.a; // => false
o.a == 'a';

B. Seal

Unlike freeze, sealing an object allows you to change the object values. But you cannot add or delete properties. And as freeze, seal is a shallow operation: you can modify inner objects and variables.

let o = {a:'a'};
Object.seal(o);
Object.isSealed(o) == true;

o.a = 'aa';
o.a == 'aa';

o.a = [];
o.a == [];

o.b = 'b';
o.b == undefined;

delete o.a; // => false
o.a == [];

C. Const

Const, on the other hand, is a different operation, it immutable binding, so you cannot assign a new value to the binding. You can not change the value of basic types since it recreates the variable. But you can modify an existing object.

const a = 'a';
a = 'b';// => Uncaught TypeError: Assignment to constant variable.

const o = {a:'a'};

o = 'a'; // => Uncaught TypeError: Assignment to constant variable.
o == {a:'a'};

o.b = 'b';
o.b == 'b';

const arr = [];
arr.push(1);
arr[0] == 1;

Conclusion, there are ways to prevent code anarchy, but you must have a strong willpower to enforce the law of correct writing.