🔴 HardType Coercion💻 Output Question

Unary plus operator

💡

Hint

Unary + is the fastest type-to-number conversion. Memorize: null→0, undefined→NaN, []→0, {}→NaN.

What does this output?

console.log(+true);
console.log(+false);
console.log(+null);
console.log(+undefined);
console.log(+'42');
console.log(+'');
console.log(+[]);
console.log(+{});

Correct Output

1
0
0
NaN
42
0
0
NaN

Why this output?

Explanation: Unary + converts to number. true→1, false→0, null→0, undefined→NaN. "42"→42, ""→0. []→""→0. {}→"[object Object]"→NaN.

Key Insight: Unary + is the fastest type-to-number conversion. Memorize: null→0, undefined→NaN, []→0, {}→NaN.

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