Category: Javascript

In React, each component can render only a single element. At the moment, there’s no way to return a multiple elements from a component’s render function.
However, if you need to render multiple components anywhere else, here are 2 solutions.
Returning Multiple Elements as an Array
It’s good practice to use helper methods or functions to generate part of your component. It’s common to want to return multiple elements from your helper method without a wrapper…

This article assumes you’re already familiar with the basics of callback hell, promises, and the Javascript event loop.
For the past few years, promises are rapidly becoming popular. They make it much easier to deal with complicated asynchronous code than callbacks. However, we can do better than promises.
Problems with promises
Promises have several issues that can make large applications difficult to understand, debug, and maintain:
You can’t abort a chain of promises
In this example, if we don’t want to run the rest of the promise chain, we use a throw to skip the processData…

I often get asked “which Javascript framework should I use?” My answer is usually “it depends, but probably React.”
jQuery
jQuery is a Javascript library that helps you perform common tasks in Javascript. jQuery used to be extremely useful because it standardized behavior across browsers. Different browsers used to behave slightly differently; jQuery made those differences go away. Nowadays, the popular browsers all behave nearly identically, so jQuery isn’t as useful…

If you’ve written enough Javascript, you’ll encounter this for sure:
Why wait for 0 milliseconds? Why not just call doSomething directly?
The answer is that this setTimeout isn’t telling the Javascript engine to run doSomething after 0ms. Rather, it’s telling the Javascript engine to run doSomething after at least 0ms. This is a key distinction for understanding how Javascript works. doSomething could run almost immediately or it could run seconds later…

Asynchronicity is arguably the hardest part of Javascript development. I’m assuming you’re already familiar with promises. If not, you can read about it and come back when you’re done. Understanding promises is crucial for modern web development.
Promises and RxJS
Promises solve Ajax callbacks very well. Remember the days when you had to handle multiple parallel Ajax requests with callbacks. How did you handle it if one fails? It probably wasn’t pretty…