JavaScript Symbol.toString() Method - JavaScript Tutorial

JavaScript Symbol.toString() Method

BLUF: This tutorial on JavaScript Symbol.toString() Method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Symbol.toString() Method

Understanding JavaScript Symbol.toString() Method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The purpose of the JavaScript Symbol.toString method is to provide a string representation of an object.

Syntax

Example

Symbol().toString();

Parameters

No Parameters.

Return value

A string that denotes the designated Symbol object.

Browser Support

Chrome 38
Safari 9
Firefox 36
Opera 25

Example 1

Example

<script>

//JavaScript to illustrate Symbol.toString

var v = Symbol("Example");

var q = Symbol("Java");

document.write(v.toString(v));

document.write("<br>");

document.write(q.toString(q)); 

//expected output: 

//Symbol(example);

//Symbol(Java);

</script>

Output:

Output

Symbol(example)

Symbol(Java)

Example 2

Example

<script>

//JavaScript to illustrate Symbol.toString

document.write(Symbol.for('DBMS').toString());

document.write("<br>");

document.write(Symbol.for('Example').toString());

//expected output: Symbol(DBMS);

//Symbol(example);

</script>

Output:

Output

Symbol(DBMS)

Symbol(example)

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience