Written by Joab Chua
Stop doing just this! ❌
Try this instead. ✅
But if you have an array of objects, try this would be even better ?
If you want to measure how fast certain operations run in your code, try this.
Do console.time and console.timeEnd to measure the time taken in the browser console.
Lastly, if you want to trace your code and its execution sequence, try this.
You will be able to see tonnes of info that you need to debug your application.
Did it happened to you before that you only need a few variables in the object but you are being passed the full object and using it in this conventional way?
Repeatedly using the human object declaration in your function? Don’t do this. Use ES6 object de-structuring instead. ✅
De-structure the variables that you need to use in the function arguments. Alternatively, you can de-structure inside the function itself.
❌ Don’t do this when you are trying to piece your variables with string.
Do this instead. ✅
Let’s say you have 2 object and you want to combined them or assign some of the properties of 1 object to another. Traditionally, we will do this.
There is technically nothing wrong with that, except that you are actually mutating your object. Try this instead. ✅
Best thing of spread operator is that it works for array as well. ?
Instead of this.
Do this instead.
Are you guilty of doing for loop this way to calculate the total amount of the cost in an array? Stop doing this. ❌
Start to change your style to this instead.
Clean and lean. Job done! ✅
Hope that these few tips will guide you along to write better, cleaner and leaner code.
Sponsored by MarsCode
Welcome to join our Discord to discuss your ideas with us.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3