Author: John Au-Yeung
1. Declare a variable using let instead of var
Using let instead of var helps protect your code from unintended consequences by limiting the scope of a variable to its intended use. Additionally, it prevents you from accidentally changing or overwriting values in your code.
By limiting the scope of your variables, you keep other parts of your program from unintentionally modifying them. This reduces the risk for errors in your program by keeping all variables within their intended scope.
2. Declare unchangeable variables using const
You can prevent changes to variables’ values by declaring them as constants using const. Doing so gives you an additional level of reassurance that these variables are not being inadvertently modified elsewhere in your code.
Then one day, the project manager on my team asked me to help him with an application that he was writing. The app, which allowed users to upload photos of their pets and have them rated by other users, was written in AngularJS. One of our engineers was out sick and they needed someone to cover for him while he recovered.
The codebase turned out to be a disaster; it had no tests and wasn’t even organized in any sensible way. I spent several days fighting with the codebase before finally figuring out what was going on. From there, I started refactoring the codebase and making improvements to its test suite.
After two weeks of working on this application, I had several pull requests open against its GitHub repo, all passing their tests and ready for review. But none of my coworkers were interested in reviewing them—they were