LESSON 16 OF 50

Choose the first available value

Use || for a simple fallback value.

Official sourceECMAScript — binary logical operatorsReviewed: 2026-08-26
STEP 1 · LEARN

How it works

The || operator returns the first operand when it is truthy; otherwise it evaluates and returns the second. An empty string is falsy, so the fallback text is chosen.

Correct example
const customLabel = '';
const label = customLabel || 'Implicit';
console.log(label);

label receives the text “Implicit”.

Common mistake
const label = customLabel && 'Implicit';

With && and a falsy first operand, the result remains the empty string.

STEP 2 · APPLY

Your exercise

Declare label as customLabel || “Implicit” and print label.

STEP 3 · RUN

Write and run the code

script.jsJAVASCRIPT
Isolated consoleisolated
Preparing the runtime…
Run the code to see the result.
The draft stays only in this browser.Isolated QuickJS · no DOM, session or network
STEP 4 · CHECK

What needs to pass

0%not checked
  • customLabel and label are declared with const.
  • label uses customLabel || the fallback.
  • The output is Implicit.
Explain the solution logic

The operator selects the fallback at runtime; the text is not printed separately.