🟑 MediumType CoercionπŸ’» Output Question

Default parameter coercion

πŸ’‘

Hint

Default parameters only trigger for undefined, not null. null is a deliberate value meaning "no object" β€” it does not fall back to the default.

What does this output?

function fn(x = 10, y = x * 2) {
  console.log(x, y);
}

fn();
fn(3);
fn(3, 5);
fn(null);
fn(undefined);

Correct Output

10 20
3 6
3 5
null NaN
10 20

Why this output?

Explanation: No args: both defaults apply, y = 10*2 = 20. fn(3): x=3, y=3*2=6. fn(3,5): both provided. fn(null): null is NOT undefined β€” x=null (NaN when doubled). fn(undefined): undefined triggers default x=10.

Key Insight: Default parameters only trigger for undefined, not null. null is a deliberate value meaning "no object" β€” it does not fall back to the default.

More Type Coercion Output Questions

🟒 EasyLoose equality coercionβ†’πŸŸ‘ MediumAddition vs concatenationβ†’πŸŸ‘ MediumFalsy values comparisonβ†’πŸŸ‘ MediumNaN comparisonβ†’

Practice predicting output live β†’

66 output questions with instant feedback

πŸ’» Try Output Quiz