The Wayback Machine - https://web.archive.org/web/20240118171729/https://www.geeksforgeeks.org/javascript-symbol-tostring-method/
Open In App
Related Articles

JavaScript Symbol toString() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The symbol.toString() is an inbuilt method in JavaScript that is used to convert the specified symbol object into the string. 

Syntax:

Symbol().toString();

Here Symbol() is the specified symbol object which is to be converted into a string. 

Parameters: This method does not accept any parameter. 

Return value: This method returns the converted string of the specified symbol object. JavaScript code to show the working of this method: 

Example-1: 

javascript




// Creating some Symbol objects
const A = Symbol('gfg');
const B = Symbol(42);
const C = Symbol();
 
// Calling toString() method
a = A.toString();
b = B.toString();
c = C.toString();
 
// Printing the strings which represent
// the above specified Symbol object
console.log(a);
console.log(b);
console.log(c);


Output:

Symbol(gfg)
Symbol(42)
Symbol()

Example-2: 

javascript




// Creating some Symbol object and
// Calling toString() method
a = Symbol('Geeks').toString();
b = Symbol.iterator.toString();
c = Symbol.for('Geeks').toString();
 
// Printing the strings which represent
// the above specified Symbol object
console.log(a);
console.log(b);
console.log(c);


Output:

Symbol(Geeks)
Symbol(Symbol.iterator)
Symbol(Geeks)

Supported Browsers:

  • Apple Safari 9
  • Edge 12
  • Firefox 36
  • Google Chrome 38
  • Opera 25

Reference: https://devdocs.io/javascript/global_objects/symbol/tostring

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 29 May, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials