Hacker News new | ask | show | jobs
by techsin101 2985 days ago
I just want to have ? Functionality in js like Ruby...

So I can do

let name = obj?.data[i]?.name;

And not get error can't read property data of undefined, when there is something wrong, just have undefined as value.

To fix this I've to write redudant checks for each level of nested property. Or do stuff like (obj || {}).prop....