Symbol.toStringTag JavaScript

The JavaScript Symbol.toStringTag property creates the default string description of an object. The Object.prototype.toString() method internally use it.

Syntax:

Symbol.toStringTag 

Example 1:

<!DOCTYPE html>
<html>
<body>
<script>    
class obj {get [Symbol.toStringTag]() {  
return 'HELLO';  }  }  
document.write(Object.prototype.toString.call(new obj()));  
</script>
</body>
</html>

Output:

[object HELLO]

Example 2:

<!DOCTYPE html>
<html>
<body>
<script>  
class TestDisplay {
  get [Symbol.toStringTag]() {
    return 'Hello W3spoint';
  }
}
 
document.write(Object.prototype.toString.call(new TestDisplay()));
 
</script>
</body>
</html>

Output:

[object Hello W3spoint]
Please Share