
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
JavaScript Symbol.toStringTag symbol
The JavaScript Symbol.toStringTag symbol is a very well known symbol that is a string valued property used for giving a description of an object during its creation
Following is the code for Symbol.toStringTag symbol −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } div { font-size: 20px; font-weight: 500; } </style> </head> <body> <h1>JavaScript Symbol.toStringTag Symbol</h1> <div class="sample"></div> <button class="Btn">CLICK HERE</button> <h3> Click on the above button to get the string description for objects </h3> <script> let fillEle = document.querySelector(".sample"); class testClass { get [Symbol.toStringTag]() { return 'Testing'; } } class helloClass { get [Symbol.toStringTag]() { return 'Hello World'; } } let test = new testClass(); let hello = new helloClass(); document.querySelector(".Btn").addEventListener("click", () => { fillEle.innerHTML += 'testClass = ' + test.toString() + "<br>"; fillEle.innerHTML += 'helloClas = ' + hello.toString() + "<br>"; }); </script> </body> </html>
Output
On clicking the “CLICK HERE” button −
- Related Articles
- JavaScript Symbol.isConcatSpreadable symbol
- JavaScript symbol.@@toPrimitive() function
- HTML5 Canvas Degree Symbol
- What is the Symbol Table?
- Hats: As a Fashion Symbol
- What is the symbol of alcohol?
- What is the symbol of battery?
- What is the symbol of mercury?
- AZX What does this symbol represent?
- Issey Miyake: Symbol of Japanese Fashion
- Sunglasses: A Timeless Symbol of Fashion
- The symbol of cadmium is CaCuCmCd
- Explain the symbol type in TypeScript
- Handmade Jewellery: A Symbol of Culture
- How to display rupee symbol in HTML

Advertisements