When to Use It (Part 2) — Smashing Magazine
Writing programs in JavaScript is accessible at the beginning. The language is forgiving, and you get used to its affordances. With time and experience working on complex projects, you begin to appreciate things like control and precision in the development flow.
Another thing you might start to appreciate is predictability, but that’s much less of a guarantee in JavaScript. While primitive values are predictive enough, objects are not. When you get an object as an input, you need to check for everything:
- Is it an object?
- Does it have that property you are looking for?
- When a property holds undefinedis it its value, or is the property itself missing?
It’s understandable if this level of uncertainty leaves you slightly paranoid in the sense that you begin to question all your choices. As a result, your code becomes defensive. You think more about whether or not you’ve handled all the wrong cases (chances are you haven’t). And in the end, your program is mostly a collection of checks rather than bringing real value to the project.
By making objects primitive, many of the potential points of failure are moved to a single place – the one where objects are initialized. If you can make sure that your objects are initialized...
source: https://news.oneseocompany.com/2023/06/05/when-to-use-it-part-2-smashing-magazine_2023060545651.html
Your content is great. However, if any of the content contained herein violates any rights of yours, including those of copyright, please contact us immediately by e-mail at media[@]kissrpr.com.