JavaScript Optional Chaining & ?? Quiz

This JavaScript quiz covers optional chaining (?.) and the nullish coalescing operator (??). You will predict what they return for missing values, compare ?? with ||, and choose the safe way to read nested data.

Easy 10 questions ~5 minutes Pass at 80% Node.js 22

Choose a mode

Playing as a guest: sign in to keep your XP and streak.

Sample question

Question 1 of 10

What does this print?

const user = { profile: null };
console.log(user.profile?.name);
Show the answer

C. undefined ?. checks the value on its left. user.profile is null, so the expression stops and returns undefined instead of throwing. Note it returns undefined, not null.

What this quiz covers

  • ?. on properties, ?.[] on indexes and ?.() on calls
  • How ?. stops the rest of the expression
  • ?? vs || with 0 and ""
  • The ??= assignment
  • Which values count as nullish

Questions people ask

Do I need an account?

No. Anyone can play. Sign in to keep your XP, streak, badges and history.

Can I retake it?

Yes. Your best score is kept, and the questions and answers are shuffled each time.