JavaScript Type Coercion Traps
When numbers become strings and values vanish into NaN
Accidental string concatenation, array sort ordering numbers alphabetically, and zero being falsely treated as missing.
Your Progress
0 of 5 completed
Challenges in this collection
- 1
Number sort puts 10 before 2
sortNumbers(arr) sorts numbers from smallest to largest. Example: sortNumbers([10, 2, 30]) → [2, 10, 30].
javascripteasy - 2
Cart total shows "01020" instead of 30
calculateTotal(items) adds up item.price for every item. The prices arrive as text, like "10". Example: prices "10" and "20" → 30.
javascripteasy - 3
Zero counter also counts "" and false
countZeros(values) counts the entries that are the number 0. Example: countZeros([0, "", false, 0]) → 2.
javascriptmedium - 4
Adding up [1, 2, 3] gives NaN
sumAll(nums) adds up every number in the array. Example: sumAll([1, 2, 3]) → 6.
javascripteasy - 5
map(parseInt) turns "10" into NaN and 2
parseAll(strings) turns a list of number strings into numbers. Example: parseAll(["10", "10", "10"]) → [10, 10, 10].
javascriptmedium
More collections to explore
Your First 5 Bugs
Five beginner-friendly bugs with clear symptoms and satisfying fixes. The best place to start if you are new to debugging.
Python Gotchas
Mutable default arguments, list.sort() returning None, and mutating a list while iterating over it.
The Off-By-One Gauntlet
Fencepost errors, inclusive vs exclusive slice bounds, and loops that step one position too far.
Async Nightmares
The asynchronous bugs that silently swallow data: un-awaited promises, forEach loops with async callbacks, and race conditions.
AI Code Comprehension
Simulate modern Code Comprehension rounds: classic coding questions written by an AI that pass the obvious test, but break on subtle edge cases.