LearnFrenzy
Sign in Take a free test

JavaScript Basics · Predict the Output · Question 10

Length of a multi-line template literal Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

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

main.js
const msg = `Line 1
Line 2`;
console.log(msg.length);
  • A 12
  • B 14
  • C 2
  • D 13 Correct
Correct Answer: Option D

Each "Line n" has 6 characters, and the line break inside the template literal is a real \n character: 6 + 1 + 6 = 13.

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