Property Access
👨💼 We need to read and work with object properties. TypeScript ensures you
can only access properties that exist on an object.
There are two ways to access properties:
// Dot notation - most common
user.name
// Bracket notation - useful for dynamic keys
user['name']
- Access properties using dot notation
- Create a function that takes a product object and returns a formatted string
- Try accessing a property that doesn't exist (see the error!)
💰 Function with object parameter:
function describe(product: { name: string; price: number }): string {
return `${product.name}: $${product.price}`
}