Replace undefined with zero

Let's assume that we declare an empty object:

let Erik = {};

// undefined

To cast an undefined variable to zero, we could use the nullish coalescing operator (ES2020):

// If childs is undefined or null, return zero
Erik.childs = Erik.childs ?? 0; 

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.