Why does node.js allow a module (or an object) specified as a constant to be changed?
For example, this is allowed:
const EXPRESS = require('express');
EXPRESS.someProperty = 'some value';
But this is not:
const MYCONST = '123';
MYCONST = '456';
const means that you cannot change the reference itself, not what the reference points to.
const a = { name: 'tom' };
// you cannot change the reference (point a to something else)
a = 5; // this is an error
// but you can change the value stored at that reference with no problem
a.name = 'bob';
const does not make the object to become immutable thus you can change the object itself but you can not assign another object to that reference
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/const
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With