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
index.ts
and:
  1. Log product.name with dot notation
  2. Log product['price'] with bracket notation
  3. Create a function formatProduct that takes an object with at least name (string) and price (number), and returns this exact string for the given product: 'TypeScript Handbook - $29.99'
  4. Leave product.rating commented out so you can see TypeScript's error if you uncomment it
  5. Export product and formatProduct
The starter already provides the product fixture. Do not change its values.

Please set the playground first

Loading "Property Access"
Loading "Property Access"