JavaScript-Quiz: Optional Chaining & ??

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.

Leicht 10 Fragen ~5 Minuten Bestanden ab 80% Node.js 22

Modus wählen

Du spielst als Gast: Melde dich an, damit XP und Serie gespeichert werden.

Beispielfrage

Frage 1 von 10

What does this print?

const user = { profile: null };
console.log(user.profile?.name);
Lösung zeigen

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.

Darum geht es in diesem Quiz

  • ?. 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

Häufige Fragen

Brauche ich ein Konto?

Nein. Jeder kann spielen. Mit Anmeldung werden XP, Serie, Abzeichen und Verlauf gespeichert.

Kann ich es wiederholen?

Ja. Dein Bestwert bleibt erhalten, und Fragen und Antworten werden jedes Mal neu gemischt.