Intermediate JavaScript
Q84 / 100

What is the difference between Symbol.toPrimitive and valueOf?

Correct! Well done.

Incorrect.

The correct answer is B) Symbol.toPrimitive receives a hint ("number", "string", "default") for context-specific conversion; valueOf is called for numeric hints without hint info

B

Correct Answer

Symbol.toPrimitive receives a hint ("number", "string", "default") for context-specific conversion; valueOf is called for numeric hints without hint info

Explanation

[Symbol.toPrimitive](hint) { if (hint === "string") return "text"; return 42; } provides full control over coercion in different contexts.

Progress
84/100