- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript symbol.description property
The symbol.description property in JavaScript converts a Symbol object to a primitive value. The syntax is as follows −
Symbol()[Symbol.toPrimitive](hint);
Example
<!DOCTYPE html> <html> <body> <h2>Demo Heading</h2> <p>Click to display...</p> <button onclick="display()">Result</button> <p id="test"></p> <script> function display() { const val = Symbol('john'); console.log(val[Symbol.toPrimitive]); } </script> </body> </html>
Output
Click the “Result” button −
Example
<!DOCTYPE html> <html> <body> <h2>Demo Heading</h2> <p>Click to display...</p> <button onclick="display()">Result</button> <p id="test"></p> <script> function display() { const val = Symbol(2465); var res = val[Symbol.toPrimitive](99); console.log(res) } </script> </body> </html>
Output
Click the “Result” button and get the result in Console −
Advertisements