I definitely recommend regularly refreshing yourself on definitions of common methods used in Javascript, for example Array.prototype.filter() Consider this code: If I saw this code I would think that the author is probably mistaken about how filter works. In some cases array methods will mutate the original array, for example Array.prototype.sort(), but filter does not… Continue reading Javascript – know your method definitions
Category: Javascript
Javascript – don’t add redundant anonymous functions
Many times I see code like this: then when it gets passed to a button element: this isn’t wrong in the sense that, the code will still run, because under the hood the DOM is still receiving a reference to a function that can be called when the click event fires, but it is more… Continue reading Javascript – don’t add redundant anonymous functions
TypeScript – browser Santa Clause
At the beginning of my career I didn’t always enjoy front end development because no matter where you turned Javascript was always lurking, and I didn’t really like it. The dynamic nature of Javascript always made me uneasy because I had been so used to Java. Thankfully the game has really changed, especially because of… Continue reading TypeScript – browser Santa Clause
TypeScript – avoid using “any”
In many Node/ React Typescript repos I have seen, the authors have opted to disable the popular linting rule that complains about using the any type. I don’t think this is a good idea, why is that? Because Typescript is just syntactic sugar I think there is sometimes a temptation to try to “get round… Continue reading TypeScript – avoid using “any”
React – cleanup, when and how?
When using features in React sometimes we need to understand the concept of cleanup. Let’s look at an example using useEffect and useState. A useEffect and component state will only exist for the lifecycle of the component, which means when a component is unmounted it will be removed from memory. There is a nice way… Continue reading React – cleanup, when and how?
Jest/React – mocking async functions
Let’s say you have a component that calls to an API in a useEffect. This API data will be used to update some component state. When writing a component test you will want to mock this API call and provide a stub for it. Many times I have seen code that looks like this: What… Continue reading Jest/React – mocking async functions
Javascript – avoid nesting ifs
When writing conditional blocks of logic try to avoid nesting, for example, consider the below: This kind of nesting can make code hard to extend, hard to read and hard to debug, so we can move everything up to the top level like:
Javascript first, React later…
React is very hot stuff right now, most aspiring web developers will probably end up looking at it. Sometimes being to eager to jump head first into a library like React means you end up having this problem: I know React but I don’t know Javascript Well why is this a problem? Not understanding the… Continue reading Javascript first, React later…