Learn JavaScript
Symbols
41.3
Lesson

Symbol and String

JavaScript does not automatically convert a symbol to a string.

Therefore, using methods like alert, which try to convert any value to a string, gives an error.

In the example given above, the first alert converts the number to a string and displays it. But the second alert gives an error because alert can only show string values.

We can use .toString() to convert a symbol to a string.

In the example given above, the alert shows the symbol as a string without giving any errors.