JavaScript · Junior · Question 14 of 75

How does count || 10 differ from count ?? 10 when count = 0?

Explanation

|| substitutes the fallback for any falsy value, while ?? only does so for null and undefined. For numbers and strings where 0 and '' are valid values, ?? is the right choice.

Further reading

Problem with a question

JavaScript · Junior · question 14

Test yourself

Take the JavaScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz