JavaScript object exercises
Objects fail in JavaScript by handing back undefined: a property that is not there, a nested value one level too deep, a counter that was never initialised and is now NaN. These exercises are short functions with one such bug each.
Find where the undefined first appears, fix it, and run the tests.
The objects bugs you will meet
- obj[key]++ on a missing key gives NaN; start it at 0.
- user.address.city crashes when address is missing; use ?. or check first.
- Assigning an object does not copy it; both names share one object.
- typeof null is "object", so a type check can let null through.
- Object keys are always strings, so obj[1] and obj["1"] are the same key.
The exercises
Medium
Errors you might be searching for
More JavaScript practice by topic
Questions
How hard are these?
Mostly medium and hard. If you are just starting, the JavaScript array exercises are a gentler place to begin.
Do they run in the browser?
Yes, in a sandboxed Web Worker. Nothing to install.