diff --git a/analyzer-comments/javascript/resistor-color-duo/prefer_extracted_top_level_constant.md b/analyzer-comments/javascript/resistor-color-duo/prefer_extracted_top_level_constant.md new file mode 100644 index 000000000..f1e5e835a --- /dev/null +++ b/analyzer-comments/javascript/resistor-color-duo/prefer_extracted_top_level_constant.md @@ -0,0 +1,14 @@ +# prefer extracted top level constant + +Consider extracting the constant to the top level scope: + +```javascript +const %{name} = %{value} + +// the rest of your code below it +export %{method.signature} +``` + +Only functions, classes and constants that are `export`ed, are visible and accessible from the outside. +These constants can live in the same file without being exposed to other code. +Also, extracting constants saves memory by avoiding repeated allocations in functions when those same constants are reused.