Better Programming

Advice for programmers.

Follow publication

Member-only story

Turn JavaScript Objects in Maps for Predictability

RayRay
Better Programming
Published in
3 min readFeb 17, 2020

--

Photo by NASA on Unsplash

The Problem With Objects

You’re deep into your code, and suddenly you get an error: “Cannot read property x of undefined.” Awww, man.

Most of the time, this means debugging — attacking my code with debugger here, console.log() there. Most of the time, I get it fixed fast. But there are those days that it takes me hours.

Example Problem

We have an object called car.

The car object has a set of key-value pairs. We get this information from our API. Normally, you’d get an events property inside the object that includes the property last_updated — stating the last time this information has been changed.

--

--

RayRay
RayRay

Written by RayRay

I’m a 🇳🇱 lead frontend developer who writes about WebDev | JavaScript | TypeScript | Vuejs | Design Systems | NuxtJS | CSS https://www.youtube.com/@devbyray

Responses (18)

Write a response