LearnFrenzy
Sign in Take a free test

String Methods · Predict the Output · Question 20

A chain of string methods Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 20 Back to Exercise

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

main.js
console.log("  Hello World From LF  ".trim().toLowerCase().split(" ").join("-"));
  • A Hello-World-From-LF
  • B hello-world-from-lf Correct
  • C -hello-world-from-lf-
  • D hello world from lf
Correct Answer: Option B

Each method returns a new string (or array) that the next method works on: trim, lower-case, split into words, join with hyphens.

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