Prefer video? See my Egghead lesson on Null Coalescing

The recent TypeScript 3.7 release introduced many people to some interesting Stage 3 JavaScript features (update: now at Stage 4!), including the nullish coalescing operator ??. Of course, you don’t need TypeScript to use it — you can either configure Babel to enable this feature, or just wait until it lands in the ECMA standard.

Let’s talk about why you’d want to use it, rather than the usual double pipe operator. Consider this example:

The boolean problem

const chickenPref = false;
const globalPref = true;
const serveUserChicken = chickenPref || globalPref; // evaluates to true

This user has been crystal clear that she does not like chicken — but the OR operator (||) doesn’t care. It will still continue and evaluate the globalPref, as if the chickenPref has not been defined. Why? Because the OR operator doesn’t care what exactly the value of the left operand is —it coerces the left operand into a boolean, and if it’s false, it’ll continue to evaluate the right one, resulting in one unhappy user. …


Image for post
Image for post

I suspect that there’s a certain personality type that is drawn to programming. The type of person that must be solving problems and learning new things, because without this drive, it’s hard to get ahead. But this career drive can be a double-edged sword, making it difficult to maintain a balance in life and prevent long-term damage to one’s health.

The secret to gaining 20 lbs

When I got my first real coding job at a Rails consultancy, there were a few lifestyle changes that came along with the new job that I didn’t pay much attention to at first, but over time had insidious consequences. For one thing, I now had a decent paycheck. I also didn’t have much free time anymore. …


Image for post
Image for post

Ant (GitHub) is much more than a React UI kit with a minimalist design aesthetic and every component under the sun. It is a rabbit’s hole that leads to a giant maze of interconnected libraries, with a serious ecosystem surrounding it. There’s a custom build tool based on Webpack called ant-tool, several CLI apps, community scaffolds, and a complete framework (dva, which has its own CLI as well). And the UI components are mini-projects in and of themselves — see this repo for information on each component.

Many of these libraries appear to be very polished, including an entire React animation library. And I’d love to learn more about them, but Ant comes with a challenge — the majority of the documentation is in Chinese. …


Warning! This design post does not contain any drawings or diagrams. It’s a different approach, but hang in there — I find that it makes it easier to remember concepts when you have to visualize them yourself.

Flexbox solves design issues that are particularly challenging on mobile, and it does so strikingly well — without requiring hacky CSS or Javascript tricks. But there’s a learning curve. The property names all sound incredibly similar and do nothing to indicate what sets them apart. On top of that, each property has a set of values that are mostly similar, yet slightly different, from each other. And to compound the confusion, not all properties of the Flexbox standard are included in React Native. …


Fetch is a fantastic networking API that was chosen for React Native, but because it is relatively new, there are a few things to be aware of when using it. The React Native Documentation does include a single example, which is a good start, but I want to add a few more things that may not be readily obvious.

GET requests

Sending a GET request to a JSON API is the simplest use case. Just call fetch and supply it with the appropriate URL. It returns a promise that can be parsed as usual:

fetch('/users.json')  
.then(function(response) {
return response.json()
})

POST requests

When submitting a POST request, supply the URL as the first argument and an object containing the request information as the second argument. …

About

Yoni Weisbrod

Developer, community contributor

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store