Don’t Use Magic Numbers

Don’t Use Magic Numbers

Tags
Clean Code
Javascript
Software Development
Published
Published May 9, 2022
Author
Due Date
☑️ Topic: Variables
 
☑️ Idea: Code should be readable and searchable. Constants should have a name. Use searchable names.
 
☑️ Benefit: Readability. Naming variables adds meaning to the program. This will help the readers understand it faster.
 
☑️ Guideline: Don’t use numbers or other hardcoded values directly, assign them to constants.
 
// BAD setTimeout(blastOff, 86400000); // What is 86400000? // GOOD // Declare them as capitalized named constants. const MILLISECONDS_PER_DAY = 60 * 60 * 24 * 1000; //86400000; setTimeout(blastOff, MILLISECONDS_PER_DAY);