Question 10
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
const params = { tags: "js,css" };
const skills = params.skills.split(",");
console.log(skills);
- A It prints []
- B TypeError: params.skills is undefined, so split cannot be called – use (params.skills ?? "").split(",") Correct
- C It prints [ '' ]
- D It prints undefined
Correct Answer: Option B
A missing property is undefined. Guard it – but note that "".split(",") gives [ '' ], so filter(Boolean) afterwards if you want an empty array.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!