Property Access
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
product.name
// Bracket notation - useful for dynamic keys
product['name']
π¨ Open
and:
- Log
product.namewith dot notation - Log
product['price']with bracket notation - Create a function
formatProductthat takes an object with at leastname(string) andprice(number), and returns this exact string for the given product:'TypeScript Handbook - $29.99' - Leave
product.ratingcommented out so you can see TypeScript's error if you uncomment it - Export
productandformatProduct
The starter already provides the
product fixture. Do not change its values.