'number' 永远不会重新分配。请改用 'const'。 (首选常量)

'number' is never reassigned. Use 'const' instead. (prefer-const)

为什么在这种情况下 eslint 4.17.0 i have error number 从未被重新分配。请改用 'const'。 (首选常量)。为什么我需要使用常量?请解释我,我不明白。

let test = {
    'number': 1,
    'string': 'asd',
};
test.number = 99;

console.log(test.number);
// output: 99

ecmascript

 {
    "parser": "babel-eslint",
    "env": {
        "browser": true
    },
    "extends": [
        "google"
    ],
    "rules": {
        "prefer-const": 2

    },
    "parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "module"
    }
}

eslint 问题

[eslint] 'test' is never reassigned. Use 'const' insted. (prefer-const)

ES6 const does not indicate that a value is ‘constant’ or immutable. A const value can definitely change. The following is perfectly valid ES6 code that does not throw an exception.

const foo = {};
foo.bar = 42;
console.log(foo.bar);
// → 42

对于您的情况,如果您知道要更改属性,请尝试使用 let。

看这里:https://mathiasbynens.be/notes/es6-const

来自 ESlint Docs:

If a variable is never modified, using the const declaration is better. Const declaration tells readers, “this variable is never modified,” reducing cognitive load and improving maintainability.

        /*eslint prefer-const: 2*/
/*eslint-env es6*/

let a = 3;               /*error 'a' is never modified, use 'const' instead.*/
console.log(a);

// `i` is re-defined (not modified) on each loop step.
for (let i in [1,2,3]) {  /*error 'i' is never modified, use 'const' instead.*/
    console.log(i);
}

// `a` is re-defined (not modified) on each loop step.
for (let a of [1,2,3]) { /*error 'a' is never modified, use 'const' instead.*/
    console.log(a);
}