The Best Way to avoid errors in Javascript -


function catchErr(fn, defaultVal) {
 try {
 return fn();
} catch (e) {
 return defaultVal;
}
}

// use it like this 
catchErr(() => unkown.properties); 

// or add an optional default value 
catchErr(() => unkown.properties, 'found err');