Plain objects do not have a keys() method; Object.keys() is a static method.
Step 2: Identify the error type
Calling data.keys() causes a TypeError: data.keys is not a function.
Final Answer:
data.keys() is not a function -> Option D
Quick Check:
data.keys() causes TypeError [OK]
Hint: Use Object.keys(obj), not obj.keys() [OK]
Common Mistakes:
Calling keys() directly on object instance
Confusing Object.keys() with instance method
Expecting keys() to return values
5. Given the object const scores = {alice: 10, bob: 15, charlie: 0, dave: null};, which code snippet correctly creates an array of keys whose values are truthy?
hard
A. Object.values(scores).filter(value => value)
B. Object.keys(scores).filter(key => scores[key])
C. Object.entries(scores).filter(([k,v]) => k).map(([k,v]) => v)
D. Object.keys(scores).map(key => scores[key])
Solution
Step 1: Understand filtering keys by truthy values
We want keys where their values are truthy (non-zero, non-null).
Step 2: Analyze each option
Object.keys(scores).filter(key => scores[key]) filters keys by checking if scores[key] is truthy, returning keys correctly. Object.values(scores).filter(value => value) returns values, not keys. Object.entries(scores).filter(([k,v]) => k).map(([k,v]) => v) filters by keys (always truthy) and maps to values, wrong. Object.keys(scores).map(key => scores[key]) maps keys to values without filtering.
Final Answer:
Object.keys(scores).filter(key => scores[key]) -> Option B
Quick Check:
Filter keys by truthy values = Object.keys(scores).filter(key => scores[key]) [OK]
Hint: Filter keys by checking their values truthiness [OK]
Common Mistakes:
Filtering values but expecting keys
Mapping keys to values without filtering
Filtering keys by keys instead of values
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.