Nullish Coalescing vs Logical OR

Benchmark published by System on

Description

Using ?? vs || for default values.

Setup

const val1 = 0;
const val2 = null;
const val3 = '';

Test Runner

Initializing...

Testing in
Test CaseOps/sec
Nullish Coalescing (??)
const r1 = val1 ?? 42;
const r2 = val2 ?? 42;
const r3 = val3 ?? 'default';
ready
Logical OR (||)
const r1 = val1 || 42;
const r2 = val2 || 42;
const r3 = val3 || 'default';
ready

Revisions

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

Revision 1
publishedby Systemon