const object, changing attributes

http://stackoverflow.com/questions/30314457/how-to-make-function-parameter-constant-in-javascript

Const will only prevent re-assigning

It will not prevent modification of the attributes of the object.

For example, this will give you an error because you are trying to reassign the variable car to another object.

But if you were to change the attribute of the object, it is valid:


You’d see honda, white

http://stackoverflow.com/questions/30314457/how-to-make-function-parameter-constant-in-javascript

Another example:

However, bear in mind that const in ES6 notation does not make the variable immutable.

is a completely valid program and a will become [1, 2, 3]. const will only prevent you from reassigning a, so that you can’t do a = [] or a = {} or whatever once const a = [1, 2]; already defined (in that particular scope).

Read Only Variable

ref – http://stackoverflow.com/questions/2821509/can-you-use-constant-variables-in-javascript

if you’re looking for a read-only variable, you simulate that with something like

and then use it like