JavaScript Symbol toString() Method
Last Updated :
29 May, 2023
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
const A = Symbol( 'gfg' );
const B = Symbol(42);
const C = Symbol();
a = A.toString();
b = B.toString();
c = C.toString();
console.log(a);
console.log(b);
console.log(c);
|
Output:
Symbol(gfg)
Symbol(42)
Symbol()
Example-2:
javascript
a = Symbol( 'Geeks' ).toString();
b = Symbol.iterator.toString();
c = Symbol. for ( 'Geeks' ).toString();
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
Share your thoughts in the comments
Please Login to comment...