Nullish coalescing with types
📖 Scenario: You are building a simple user profile display. Sometimes, the user data might be missing or undefined. You want to safely provide default values using nullish coalescing.
🎯 Goal: Create a TypeScript program that uses nullish coalescing to assign default values to possibly undefined user properties.
📋 What You'll Learn
Create an object with user data that may have undefined properties
Create a default value variable for the user's city
Use nullish coalescing to assign a city value safely
Print the final city value
💡 Why This Matters
🌍 Real World
Nullish coalescing helps handle missing or undefined data safely, common in user input or API responses.
💼 Career
Understanding nullish coalescing is important for writing robust TypeScript code that avoids bugs from undefined or null values.
Progress0 / 4 steps