LearnFrenzy
Sign in Take a free test

String Methods · Find the Error · Question 10

Error: splitting a missing value Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

The code below stops with an uncaught error. Which statement correctly describes the problem?

main.js
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links