Assigning value: Conditional operator ( ? : ) vs Optional chaining and Nullish coalescing ( ?? )

Benchmark created on


Description

Test created by @Logos

Setup

const arr = undefined;

Test runner

Ready to run.

Testing in
TestOps/sec
Conditional operator
const value = arr ? arr[0] : null;
ready
Optional chaining and Nullish coalescing
const value = arr?.[0] ?? null;
ready

Revisions

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