BeginnerCoder

Lesson 6 — Config defaults

|| versus ??

Two ways to give a default:

  • a || b uses b if a is falsy — that includes 0, "" and false;
  • a ?? b uses b only if a is null or undefined.

So with retries: 0, config.retries || 3 gives 3 (wrong — the user asked for 0), while config.retries ?? 3 gives 0.

Why it matters: a config value of 0 or false is a real choice; ?? respects it.

Want it another way?
Task

Change both lines to use ?? so retries stays 0 and debug stays false.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.