LearnFrenzy
Sign in Take a free test

JavaScript Basics · Predict the Output · Question 8

Comment characters inside a string Answer, explanation & discussion

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

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

main.js
console.log("// not a comment"); // a real comment
console.log("/* also text */");
  • A /* also text */
  • B // not a comment /* also text */ Correct
  • C Nothing is printed
  • D // not a comment // a real comment /* also text */
Correct Answer: Option B

Inside a string literal, // and /* are ordinary characters. Only the // after the statement starts a comment.

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