Common Bugs with Data Types

📌 Common bugs · data-types✍️ Written by Tom Reyes📅 Reviewed 2026-04-10⏱ ~7 min read

Type-coercion and conversion bugs hit every beginner. These five are the most expensive.

Bee mascot
From Bee: "I see this exact bug in beginners every week. Read it once, and you'll spot it on yourself before it bites."
#1

Adding a string and a number in JS

js
const total = "5" + 3;
console.log(total); // "53", not 8
⚠️
Why this happens
JavaScript coerces 3 to a string and concatenates.
The fix
Always parse user input: Number(input) + 3. Or use TypeScript.
#2

Form input always being a string

js
const age = document.getElementById("age").value;
if (age > 18) {  // sometimes wrong
  ...
}
⚠️
Why this happens
.value is always a string. "5" > 18 is false; "100" > 18 is also false.
The fix
Convert: const age = Number(input.value). Validate the result is not NaN.
#3

typeof null is "object"

js
console.log(typeof null);  // "object" — famous bug
⚠️
Why this happens
A historical mistake in JS. Never fixed for backward compatibility.
The fix
For null checks, use x === null. For "is this anything," use x != null.
#4

Mixing int and float division

py
print(5 / 2)    # 2.5 (Python 3)
print(5 // 2)   # 2  (integer division)
⚠️
Why this happens
/ always returns a float in Python 3. // truncates.
The fix
Pick the operator deliberately. In Java, integer / integer truncates by default — use 5.0 / 2 for floats.
#5

NaN never equals itself

js
console.log(NaN === NaN);  // false!
⚠️
Why this happens
NaN is the only value not equal to itself.
The fix
Use Number.isNaN(x) or isNaN(x) instead of comparison.
💡
Want the full lesson?

Read Data Types — the complete lesson, or test yourself with the quiz.

T
Tom Reyes
Reviewer · 12 yrs Java/JVM

Tom spent eight years as a backend engineer in fintech (Java + Kotlin) and four as a lead at an enterprise SaaS company. He reviews every Java example on this site and writes the data-structure deep dives. He cares deeply that beginners aren't taught bad habits they'll have to unlearn. More about Tom →