

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Conditionals
incomplete
2: Comparison Operators
incomplete
3: Logical Operators
incomplete
4: Switch
incomplete
5: Ternary Operator
incomplete
6: When to Ternary
incomplete
7: Truthy and Falsy
incomplete
8: Nullish Coalescing
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
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.
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".