optional chaining null inside

Benchmark created by erykpiast on


Setup

const foo={bar:{baz:null}};
  function dlv(n,t,o,i,l){for(t=t.split?t.split("."):t,i=0;i<t.length;i++)n=n?n[t[i]]:l;return n===l?o:n}

Test runner

Ready to run.

Testing in
TestOps/sec
old spice
foo && foo.bar && foo.bar.baz && foo.bar.baz.qux
ready
dlv (string)
dlv(foo, "bar.baz.qux");
ready
dlv (array)
dlv(foo, ['bar', 'baz', 'qux']);
ready
optional chaining (TypeScript)
var o,l,v;null===(v=null===(l=null===(o=foo)||void 0===o?void 0:o.bar)||void 0===l?void 0:l.baz)||void 0===v||v.qux
ready
optional chaining (Babel)
var l,n;null==foo||null===(l=foo.bar)||void 0===l||null===(n=l.baz)||void 0===n||n.qux
ready
optional chaining (native)
foo?.bar?.baz?.qux;
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by erykpiast on