Premium content for subscribers only.
People of all programming backgrounds use JavaScript. lingua franca of the web, at some point in their career. So even if it contains some nasty elements, you have to accept them and learn how to avoid the bad parts. Arguably, you can write good code in JavaScript if you understand the language’s pitfalls and avoid them. ‘Javascript: the good part” is an excellent book on this topic.
JavaScript is particularly difficult to code because it’s a completely failed language design that people started using for a different purpose than it was originally intended for. It’s been around for almost 30 years that can’t be discarded or revisited because almost the entire web runs on this technology and backwards incompatible changes could affect millions of users. is the embodiment of the decision of
Here are six pain points you can avoid to write good code in Javascript.
code architecture
You don’t have to be a master software architect, but at least do some basic planning and put the pieces together without a ton of tools. Expecting frameworks and other tools to do that is not very impressive.
Download mobile app
Because JavaScript and HTML omit some basic constructs and components that are commonly required, these libraries often duplicate features and functionality. This also means that some people are not very good at playing together. It can be frustrating to choose from too many options as it ultimately determines the fate of the product.
Manage dependencies
Most JavaScript projects start off ambitious and avoid using too many NPM packages. However, even if you do your best, your luggage will pile up. Package.json lines grow over time and package-lock.json looks horrible with the number of pull requests added or removed as dependencies are added.
Avoid the main package registry (NPM, yarn) as the sole source of dependencies. It can crash, go down, or lose packages. On the other hand, it may not be possible to access due to network problems, etc. Avoid the package registry becoming a single point of failure for your project. To minimize these risks, use dedicated proxies or local repositories.
State management
All data managed by the app when the user interacts with the app is the app state. Every app always has a state. This is probably why newbies don’t understand it. States are in so many places that they are difficult to define precisely. But when you look at the examples and understand what it is, you realize it’s all over the place.
All applications have state, even those written in plain JavaScript. This is not a concept unique to JS libraries. You need to understand whatever app you are trying to build. Unfortunately, state management feels like a black box to many. State management is therefore one of the most complex topics in modern JavaScript-centric front-end development.
data management
JavaScript automatically allocates memory when an object is created and frees it when it is no longer in use. Unfortunately, this can be confusing. It can give developers the false impression that they don’t need to worry about memory management.
In general, not worrying enough about memory management will not have noticeable consequences for “outdated” web pages. However, advances in SPA (Single Page Application) encourage attention to memory-related coding practices. When applications start using more and more memory, it can severely impact performance and even crash browser tabs.
debug
JavaScript is the web language used by over 90% of websites. Still, it has a reputation for being difficult to debug. Unfortunately, the great thing about JavaScript is that it also makes debugging frustrating. For example, its asynchronous nature makes it easy to manipulate the DOM in response to user events, but it also makes it difficult to identify problems.
You can’t debug JavaScript without tools like alert(), Postman, Raygun, Chrome console, etc. But these tools can also cause problems.
Search for packages
of NPM website That’s excellent. You can search all published packages to get various information such as documentation, GitHub links, general data (versions, number of issues, date of last publication). However, choosing the right package for your project may require more than this. A complete overview is needed for more efficient selection.
Choosing the right package from the myriad of modules can be a daunting task. For example, you want to know if a package is popular enough, well-maintained, community-supported, and completely secure.