
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 ValueOf Function
The JavaScript symbol.valueOf() function returns the primitive value of a symbol object.
Following is the code for implementing symbol.valueOf() function −
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.valueOf() function</h1> <div class="sample"></div> <button class="Btn">CLICK HERE</button> <h3> Click on the above button to get the value of symbols </h3> <script> let fillEle = document.querySelector(".sample"); const symbol = Symbol('computer'); const symbol1 = Symbol(234); let res = symbol.valueOf(); let res1 = symbol1.valueOf(); document.querySelector(".Btn").addEventListener("click", () => { fillEle.innerHTML += 'res = ' + res.toString() + "<br>"; fillEle.innerHTML += 'res1 = ' + res1.toString() + "<br>"; }); </script> </body> </html>
Output
On clicking the “CLICK HERE” button −
Advertisements