fork download
  1. var g = {};
  2.  
  3. console.log(g);
  4. console.log(g.a);
  5.  
  6. function t(func, fallbackValue) {
  7. try {
  8. var value = func();
  9. return (value === null || value === undefined) ? fallbackValue : value;
  10. } catch (e) {
  11. return fallbackValue;
  12. }
  13. }
  14.  
  15. console.log(t(() => g.a.b), 'null');
Success #stdin #stdout 0.03s 16772KB
stdin
Standard input is empty
stdout
[object Object]
undefined
undefined null