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.
- Return the
primaryvalue if it is truthy. - If not, return the
secondaryvalue if it is truthy. - If neither are truthy, return the
backupvalue even if it is falsy.
01EXAMPLE 1
Input
primary = 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
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
primarynull
secondary"B"
backup"C"
Expected Output
B
Click RUN to test your solution