Scripter Javascript Tutorial
javascriptmusiclogicscripterbookexcerpttutorial77 DRY: Don’t Repeat Yourself
Wherever possible, try not to duplicate code and variable values. If
code is duplicated in multiple places and an error is found in one
place, then every other instance of the code or value will need to be
reviewed. If code needs to be used in more than one place, then put it
in a function. If a value needs to be used in more than one place, then
make it a const
at the top of the script (in the global
space).
With both code and values in a single place, then making changes and fixing bugs is faster because it only has to get changed once. By storing values in a variable and reusing the variable, misspellings are less of an issue because when the variable is misspelled it technically doesn’t exist, so Scripter will catch the mistake and throw an error. Scripter has no way of checking for misspellings in strings or whether a typed number is correct or not.