From 52b4a068e5b42d842fbdfb654d5f6666ac153eab Mon Sep 17 00:00:00 2001 From: Frans Date: Thu, 20 Feb 2025 20:09:23 +0200 Subject: [PATCH] Add prefer_extracted_top_level_constant analyzer comment to javascript resistor color duo (exercism/javascript-analyzer#127) --- .../prefer_extracted_top_level_constant.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 analyzer-comments/javascript/resistor-color-duo/prefer_extracted_top_level_constant.md 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..83d59c238 --- /dev/null +++ b/analyzer-comments/javascript/resistor-color-duo/prefer_extracted_top_level_constant.md @@ -0,0 +1,15 @@ +# 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 const decodedValue = (...) +``` + +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.