Optional Chaining

Benchmark published by System on

Description

Optional chaining ?. vs Logical AND &&.

Setup

const obj = { a: { b: { c: { d: 42 } } } };
const nullObj = { a: null };

Test Runner

Initializing...

Testing in
Test CaseOps/sec
Optional Chaining
const val1 = obj?.a?.b?.c?.d;
const val2 = nullObj?.a?.b?.c?.d;
ready
Logical AND
const val1 = obj && obj.a && obj.a.b && obj.a.b.c && obj.a.b.c.d;
const val2 = nullObj && nullObj.a && nullObj.a.b && nullObj.a.b.c && nullObj.a.b.c.d;
ready

Revisions

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

Revision 1
publishedby Systemon