This article will help you to avoid mistakes that are difficult (or just tiresome) to fix later. If you are going to create a new project and want to

Mastering Angular: Essential Code Organization Principles

submited by
Style Pass
2023-03-22 13:00:09

This article will help you to avoid mistakes that are difficult (or just tiresome) to fix later. If you are going to create a new project and want to make it amazing — keep reading!

Functions that use keyword this are not pure — they use information outside of their scope, so they can return different results for the same arguments.

Nonetheless, some of our functions, obviously, have to use this — still, try to move as much of your code as possible from impure functions to pure functions.

Accidental mutations of data are the biggest source of bugs, that’s why the JS community created tools to provide immutability for data structures. You can find them and read their documentation if you like (at least reading about them is a good idea, anyway).

I’ll show you one trick that will be “good enough” in many cases — it will not save you from every mistake (as immutability tools would), but it will cover the absolute majority of cases, and it will cost you nothing:

Leave a Comment