HomeLanguagesJavascriptJavaScript Symbol toStringTag Property

JavaScript Symbol toStringTag Property

The Symbol.toStringTag is a well-known symbol and string-valued property in JavaScript which is used in the creation of the default string description of an object.

Syntax: 

Symbol.toStringTag

Parameters: This does not take any parameter.

Return value: This returns the String Object.

Example 1: In this example, we will use Symbol toStringTag Property

javascript




// Illustrating Symbol.toStringTag 
console.log(Object.prototype.toString.call('Geeks'));
console.log(Object.prototype.toString.call("Geeks"));
console.log(Object.prototype.toString.call([1, 2, 3, 4]));
console.log(Object.prototype.toString.call(5));
console.log(Object.prototype.toString.call(true));
console.log(Object.prototype.toString.call(false));
console.log(Object.prototype.toString.call(undefined));
console.log(Object.prototype.toString.call(null));


Output

[object String]
[object String]
[object Array]
[object Number]
[object Boolean]
[object Boolean]
[object Undefined]
[object Null]


Example 2: In this example, we will use Symbol toStringTag Property

javascript




// Illustrating Symbol.toStringTag 
class ToString {
    get [Symbol.toStringTag]() {
        return 'neveropen';
    }
}
 
// Getting the string description of the object
console.log(Object.prototype.toString.call(new ToString()));


Output

[object neveropen]


Supported Browsers: 

  • Google Chrome 49
  • Firefox 51
  • Edge 15
  • Opera 36 and above
  • Apple Safari 10 and above

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32712 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7086 POSTS0 COMMENTS
Nicole Veronica
12225 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12309 POSTS0 COMMENTS
Shaida Kate Naidoo
7202 POSTS0 COMMENTS
Ted Musemwa
7467 POSTS0 COMMENTS
Thapelo Manthata
7187 POSTS0 COMMENTS
Umr Jansen
7171 POSTS0 COMMENTS