Exporting mutable 'var' binding, use 'const' instead
60import { ValveType } from "./app/core/init";
61import { test } from "mocha";
62
63export var PRIMITIVES_SERVER = false; 64
65export function enablePrimitiveServer() {
66 PRIMITIVES_SERVER = true;
Description
It is recommended not to mutate a name after exporting it. That is to avoid using mutable variable declarator kinds like let
and var
, which can be mutated even after exporting the name. This creates unexpected results when using the name in the module where it is being imported.
This can be unexpected errors like this.
// <!-- utils.js -->
export let magicNumber = 2
magicNumber = 3
And when using this
// <!-- index.js -->
import { magicNumber } from './utils.js;
console.log(magicNumber) // we might be expecting here the value 2, but it would be 3
Bad Practice
// <!-- config.js -->
export let retryLimit = 2 // it is recommended to use `const` instead
Recommended
// <!-- config.js -->
export const retryLimit = 2