Navigation

Programming

Variables and Data Types: My Late-Night Debugging Stories

The Night I Learned About Type Coercion What Are Variables, Really? The Type System Spectrum Dynamic Typing (Python, JavaScript) Static Typing (TypeScript, Go) Data Types: The Seattle Developer’s Guide Primitive Types Complex Types Memory and References: The Apartment Analogy Type Conversion:...
Jul 05, 2025
7 min read

Variables and Data Types: My Late-Night Debugging Stories

It’s 2 AM at my Capitol Hill apartment, and I’m staring at my screen with my third bubble tea of the night (brown sugar, 50% sweet, as always). The error message mocks me: TypeError: Cannot read property 'name' of undefined.

Sound familiar? Let me tell you, after seven years in tech and countless debugging sessions at various Seattle coffee shops, I’ve learned that most bugs trace back to misunderstanding variables and data types. So grab your coffee (or bubble tea), and let’s dive into the fundamentals that would have saved me so many late nights.

The Night I Learned About Type Coercion

Back when I was at Amazon, fresh out of UW with my shiny Master’s degree, I wrote this innocent-looking JavaScript code:

let userId = prompt("Enter your user ID:");
let bonusMultiplier = 2;
let bonus = userId + bonusMultiplier;
console.log("Your bonus is: " + bonus);

User enters 100, expecting a bonus of 102. What do they get? "1002".

My senior engineer looked at my code, chuckled, and said, “Welcome to JavaScript’s type coercion party.” That was my introduction to the wild world of dynamic typing.

What Are Variables, Really?

Think of variables as labeled boxes in your apartment. I have a box labeled “winter gear” (because Seattle), another labeled “tea collection” (because Taiwanese), and one mysteriously labeled “cables” (because developer).

In programming, it’s the same concept:

# Python - my first love
winter_gear = ["rain jacket", "umbrella", "waterproof boots"]
tea_collection = {"oolong": 5, "jasmine": 3, "bubble_tea_powder": 10}
mysterious_cables = None  # We all have that drawer
// JavaScript - my daily driver
const winterGear = ["rain jacket", "umbrella", "waterproof boots"];
let teaCollection = new Map([["oolong", 5], ["jasmine", 3]]);
var mysteriousCables = undefined; // Please don't use var in 2025

The Type System Spectrum

After working at both Amazon and Microsoft, I’ve seen how different type systems affect large-scale development. Here’s my take:

Dynamic Typing (Python, JavaScript)

Like ordering at Din Tai Fung without looking at the menu - flexible, quick, but sometimes you get surprised.

# Python lets you be free
weather = "rainy"
weather = 45  # Now it's temperature
weather = ["rain", "clouds", "more rain"]  # Now it's a forecast

Static Typing (TypeScript, Go)

Like having a detailed order form - more upfront work, but you know exactly what you’re getting.

// TypeScript at my fintech startup
interface User {
  id: string;
  balance: number;
  lastLogin: Date;
}

let user: User = {
  id: "maya123",
  balance: 1000.50,
  lastLogin: new Date()
};
// user = "maya"; // ❌ TypeScript says no

Data Types: The Seattle Developer’s Guide

Primitive Types

Numbers: In fintech, precision matters. I learned this the hard way when a floating-point error cost us $0.01 on thousands of transactions.

// The classic floating-point surprise
console.log(0.1 + 0.2); // 0.30000000000000004 

// What we do at RainCity FinTech
const addMoney = (a, b) => {
  return Math.round((a + b) * 100) / 100;
};

Strings: Text data, but with quirks in every language.

# Python strings are immutable
coffee_order = "flat white"
# coffee_order[0] = "F"  # This won't work!
coffee_order = coffee_order.capitalize()  # Create new string

# Multi-line strings for those long SQL queries
query = """
SELECT user_id, balance
FROM accounts
WHERE last_login > '2025-01-01'
AND city = 'Seattle'
"""

Booleans: The yes/no of programming. But watch out for “truthy” and “falsy” values!

// JavaScript's truthiness at 2 AM is dangerous
if ("") console.log("Empty string is truthy"); // Won't print
if ("0") console.log("String '0' is truthy"); // Will print!
if ([]) console.log("Empty array is truthy"); // Will print!

// My rule: Be explicit
if (userList.length > 0) {
  // Much clearer than if (userList.length)
}

Complex Types

Arrays/Lists: Ordered collections. In Seattle weather terms:

# Python list
seattle_weather = ["rain", "cloudy", "rain", "partly cloudy", "rain"]

# Finding sunny days (good luck)
sunny_days = [day for day in seattle_weather if day == "sunny"]
print(f"Sunny days: {len(sunny_days)}")  # Sunny days: 0

Objects/Dictionaries: Key-value pairs. Perfect for modeling real-world data:

// My typical coffee shop coding session
const codingSession = {
  location: "Victrola Coffee Roasters",
  duration: "3 hours",
  caffeineConsumed: {
    coffee: 2,
    bubbleTea: 1
  },
  linesOfCode: 250,
  bugs: 3,
  bugsFixed: 2.5  // That 0.5 is still haunting me
};

Memory and References: The Apartment Analogy

This concept clicked for me when I thought about my Seattle apartment:

# Primitive types = Moving boxes
my_floor = 15
friends_floor = my_floor  # Copy the value
friends_floor = 20  # My floor stays 15

# Reference types = Apartment keys
my_plants = ["monstera", "pothos", "dying succulent"]
roommates_plants = my_plants  # Sharing the same reference
roommates_plants.append("another dying succulent")
print(my_plants)  # Now I have 4 plants (2 dying)

Type Conversion: Handle with Care

Working in fintech taught me that type conversion is where money gets lost:

// The dangerous way
let userInput = "100.50";
let amount = +userInput;  // Unary plus - quick but risky

// The safe way
function parseMoneyAmount(input) {
  const parsed = parseFloat(input);
  if (isNaN(parsed)) {
    throw new Error(`Invalid amount: ${input}`);
  }
  return Math.round(parsed * 100) / 100;  // Round to cents
}

Scope: The Coffee Shop Rule

I think of scope like coffee shop conversations:

function coffeeShopCoding() {
  const wifiPassword = "FlatWhite2023";  // Only known inside
  
  if (true) {
    const laptopBattery = "15%";  // Block scope
    let panicLevel = "high";
  }
  
  // console.log(laptopBattery);  // ❌ Can't access
}

// console.log(wifiPassword);  // ❌ What happens in coffee shop...

Real-World Lessons

The Payment Processing Bug

Last month at RainCity FinTech, we had a bug where payments were randomly failing. The culprit?

// The bug
if (payment.amount === userBalance) {  // Comparing float with float
  processPayment();
}

// The fix
const EPSILON = 0.001;
if (Math.abs(payment.amount - userBalance) < EPSILON) {
  processPayment();
}

The Null vs Undefined Debate

// My team's convention
let userData = null;  // Explicitly no data
let apiResponse;      // Undefined - not yet assigned

// Checking for both
if (userData == null) {  // Checks both null and undefined
  // Fetch user data
}

Best Practices from the Trenches

  1. Use Descriptive Names: u might save keystrokes, but currentUser saves debugging time
  2. Initialize Variables: Undefined variables at 2 AM are not fun
  3. Const by Default: In JavaScript, start with const, use let when needed
  4. Type Annotations: Even in dynamic languages, comments help:
    def calculate_tax(amount: float, rate: float) -> float:
        """Calculate tax for Seattle (no state income tax!)"""
        return amount * rate
    

The Taiwanese Mom Test

My mom always asks, “Can you explain what you do?” If I can’t explain variables to her, do I really understand them? Here’s my attempt:

“媽, variables are like labeled jars in your kitchen. You have one for rice, one for tea, one for those red envelopes. In programming, instead of rice, I put numbers or text or lists of things. And just like how you label everything clearly in Chinese and English, I name my variables clearly so other programmers (and future me) know what’s inside.”

She gets it. And honestly, that’s all variables really are.

Wrapping Up

Seven years ago, as a confused international student debugging my first real application at 3 AM, I wish someone had told me: most bugs aren’t because you’re bad at logic. They’re because you misunderstood what type of data you’re working with.

Now, whenever I mentor new developers (especially those late-night debugging sessions at the Seattle library), I start with variables and types. Get these right, and you’ll save yourself countless hours and bubble tea runs.

Next time you’re debugging at 2 AM, check your types first. Your future self will thank you.


Currently writing this from Victrola Coffee Roasters on 15th Ave, where the wifi is strong and the flat whites are perfect. What’s your worst type-related bug story? Find me on Twitter @maya_codes_pnw - I love a good debugging horror story!

Share this article

Add Comment

No comments yet. Be the first to comment!

More from Programming