LearnFrenzy
Sign in Take a free test

Data Types · Find the Error · Question 8

Error: joining a symbol to a string Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

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

main.js
const orderId = Symbol("order-42");
console.log("Processing " + orderId);
  • A TypeError: a Symbol cannot be converted to a string implicitly – use orderId.toString() or orderId.description Correct
  • B It prints Processing Symbol(order-42)
  • C It prints Processing order-42
  • D It prints Processing undefined
Correct Answer: Option A

Symbols refuse implicit string conversion so they are not accidentally used as text. String(orderId) or orderId.toString() gives "Symbol(order-42)"; orderId.description gives "order-42".

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