Short-Circuit Chain

MediumAcc. 82.9%
+35 XP 10

The Fallback Chain

In professional code, we often want to grab the first "valid" (truthy) piece of data from a sequence of possibilities. This is done by chaining the || operator.

The Assignment

Your function receives three parameters: primary, secondary, and backup.

  1. Return the primary value if it is truthy.
  2. If not, return the secondary value if it is truthy.
  3. If neither are truthy, return the backup value even if it is falsy.

01EXAMPLE 1

Inputprimary = null, secondary = "Target", backup = "Final"
Output"Target"

Explanation: Primary is null (falsy), so it grabs "Target".

Constraints

  • Use logical short-circuiting.
  • Do not use if/else.
LogicShort-CircuitMastery
JavaScript
Loading...
3 Hidden

Input Arguments

primarynull
secondary"B"
backup"C"

Expected Output

B

Click RUN to test your solution