We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Nullish Coalescing

JavaScript is truly a language built for the web, and the web runs on... uncertainty.

It's kinda crazy how much production JavaScript exists solely to handle cases where a value might be null or undefined.

The nullish coalescing operator ?? is a way to handle these cases in a more concise way.

let myName = null;
console.log(myName ?? "Anonymous"); // "Anonymous"

myName = "Lane";
console.log(myName ?? "Anonymous"); // "Lane"

If the value on the left of ?? is null or undefined, the value on the right is returned. Otherwise, the value on the left is returned. It's a way to set sane defaults for variables that might be empty.

Assignment

Certain users in the Textio database don't have a subscriptionType, by default customers who aren't subscribed are considered a "Guest". Use a nullish coalescing operator to fix the code that starts on line 9 so that an empty subscriptionType defaults to "Guest".