Run details:
Mozilla/5.0 (Linux; Android 10; SAMSUNG SM-G981W) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/12.1 Chrome/79.0.3945.136 Mobile Safari/537.36
Chrome Mobile 79
Android
Mobile
4 years ago
Test name Executions per second
Optional Chaining 1429144.0 Ops/sec
Lodash 623419.7 Ops/sec
Script Preparation code:
AخA
 
var obj = {a: {b: {c: {d: 1}}}}
var badObj = {}
Tests:
  • Optional Chaining

     
    (obj.a == null ? undefined : obj.a.b == null ? undefined : obj.a.b.c == null ? undefined : obj.a.b.c.d) || 2
    (badObj.a == null ? undefined : badObj.a.b == null ? undefined : badObj.a.b.c == null ? undefined : badObj.a.b.c.d) || 2
  • Lodash

     
    _.get(obj, "a.b.c.d", 2)
    _.get(badObj, "a.b.c.d", 2)