LearnFrenzy
Sign in Take a free test

String Methods · Predict the Output · Question 7

Splitting an empty string Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 7 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
console.log("".split(","), "".split(""), "".split(",").length);
  • A [ '' ] [] 1 Correct
  • B [] [] 0
  • C [ '' ] [ '' ] 1
  • D [] [ '' ] 0
Correct Answer: Option A

Splitting "" on a separator gives one empty piece (a common bug when counting CSV fields); splitting it into characters gives 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