← Back to Demo Hub
Test #15Data Handling

Number Method on Undefined

Calling number methods like toFixed() on undefined values.

📋 Demo Instructions

  1. Click the "Trigger Error" button below
  2. Open browser console (F12) to see the error
  3. Wait 5-10 seconds for the error to be captured
  4. Go to Dashboard → Performance Monitoring
  5. Click "Fix with Carla" on the error
  6. Review the generated PR
🌍 Real-World Scenario
API returns product/order data with missing price, amount, or discount fields. Common when products are out of stock, prices are being updated, or the field is optional in the database schema.
✅ Expected Fix
Add default value (0) or null check before calling number methods. Use optional chaining with nullish coalescing.
Fix Confidence:HIGH

💻 Buggy Code

// Buggy Code
const product = await fetchProduct(id);
const displayPrice = product.price.toFixed(2);
// TypeError: Cannot read properties of undefined (reading 'toFixed')

// API returned product without price field
// { name: 'Widget', description: '...' }

🔴 Error Log

Waiting for error to be triggered...