Here is a interesting fact, do you know which is the worlds most hated and most loved programming language .......? 🙄
- Interpreted instead of Compiled
- Supports Promises and Closures and many more.
For avoiding this kinds of situation, here is the list of best practices, which anyone can follow to avoid the future mistakes.
👉 one thing, I want to mention is, this may not be worlds best article for best practices, but I will definitely make it as good as possible.
Understanding the scoping of variables is pretty important while coding. Variables declared with let are specifically blocked scope. Whereas, if you used var then you can hoist it anywhere in your code, but using var should be avoided as much as possible (suggested by many !).
But, I escalate this suggestion only when there is nothings seems working or scenarios where, I have to manipulate the global variables based of the events like
- If exception occurs print log and terminate programme using
It is still pretty confusing for me to know how this works, but if you wanna use it then know it perfectly.
This is the principal everyone should follow in their programming paradigm. Creating pure functions and causing less side effects on the external world, makes the function more reusable and robust. If function is no longer making any side effects on the global context or the data present outside the body of the function, then it can be easily swapped out, reused and manipulated with ease
Handling the API responses blindly can easily lead us to the end game or late night forceful fixes. Always handle the API response with null coalescing operators or default initialization of the variables.
for ex .
Know more about Null Coalescing Operators Here
IIEF stands for " Immediately Invoking Function Expression". It's comes pretty handy if you want to make your isolated from the global context. Take a look at here
IIEF keeps the variable inside the context and avoids the hoisting.
Using Promises is pretty standard practice now. But, anyone using callback-only approach must take a look at here.
- Inversion of Control trust loss
🏵 Final Thoughts 🏵
Thanks for reading 🙏