节点JS允许更改常量

Aze*_*edo 3 javascript node.js ecmascript-6

为什么node.js允许更改指定为常量的模块(或对象)?

例如,允许这样做:

const EXPRESS = require('express');
EXPRESS.someProperty = 'some value';
Run Code Online (Sandbox Code Playgroud)

但这不是:

const MYCONST = '123';
MYCONST = '456';
Run Code Online (Sandbox Code Playgroud)

nem*_*035 6

const 意味着您无法更改引用本身,而不能更改引用所指向的内容.

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';
Run Code Online (Sandbox Code Playgroud)